azure_storage_blobs/options/
block_id.rs

1use azure_core::{base64, AppendToUrlQuery, Url};
2use bytes::Bytes;
3
4/// Struct wrapping the bytes of a block blob block-id,
5///
6/// A block id cannot exceed 64 bytes before encoding. In addition all block id's in a block list must be the same length.
7/// Reference: <https://learn.microsoft.com/en-us/rest/api/storageservices/put-block#uri-parameters>
8///
9#[derive(Debug, Clone, PartialEq, Eq)]
10pub struct BlockId(Bytes);
11
12impl BlockId {
13    /// Returns a new block id,
14    ///
15    pub fn new(block_id: impl Into<Bytes>) -> Self {
16        Self(block_id.into())
17    }
18
19    /// Returns clone of bytes,
20    ///
21    pub fn bytes(&self) -> Bytes {
22        self.0.clone()
23    }
24}
25
26impl AppendToUrlQuery for BlockId {
27    fn append_to_url_query(&self, url: &mut Url) {
28        url.query_pairs_mut()
29            .append_pair("blockid", &base64::encode(&self.0));
30    }
31}
32
33impl<B> From<B> for BlockId
34where
35    B: Into<Bytes>,
36{
37    fn from(v: B) -> Self {
38        Self::new(v)
39    }
40}
41
42impl AsRef<[u8]> for BlockId {
43    fn as_ref(&self) -> &[u8] {
44        self.0.as_ref()
45    }
46}