pub type Bytes<const N: usize, LenT = usize> = BytesInner<LenT, OwnedBytesStorage<N>>;
Aliased Type§
pub struct Bytes<const N: usize, LenT = usize> { /* private fields */ }
Implementations§
Source§impl<const N: usize, LenT: LenType> Bytes<N, LenT>
impl<const N: usize, LenT: LenType> Bytes<N, LenT>
Sourcepub const fn const_capacity(&self) -> usize
pub const fn const_capacity(&self) -> usize
Get the capacity of the buffer.
Always equal to the N
const generic.
Sourcepub fn increase_capacity<const M: usize>(&self) -> Bytes<M, LenT>
pub fn increase_capacity<const M: usize>(&self) -> Bytes<M, LenT>
Copy the contents of this Bytes
instance into a new instance with a higher capacity.
let bytes32: Bytes<32> = Bytes::from([0; 32]);
let bytes64: Bytes<64> = bytes32.increase_capacity();
assert_eq!(bytes64.len(), 32);
assert_eq!(bytes64.capacity(), 64);
Decreasing the capacity causes a compiler error:
ⓘ
let bytes32: Bytes<32> = Bytes::from([0; 32]);
let bytes16: Bytes<16> = bytes32.increase_capacity();
pub fn cast_len_type<NewLenT: LenType>(self) -> Bytes<N, NewLenT>
Trait Implementations§
Source§impl<'de, const N: usize, LenT: LenType> Deserialize<'de> for Bytes<N, LenT>
impl<'de, const N: usize, LenT: LenType> Deserialize<'de> for Bytes<N, LenT>
Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl<const N: usize, const M: usize, LenT: LenType> From<&[u8; M]> for Bytes<N, LenT>
Construct a Bytes<N>
instance by copying from an array with N
or less elements.
impl<const N: usize, const M: usize, LenT: LenType> From<&[u8; M]> for Bytes<N, LenT>
Construct a Bytes<N>
instance by copying from an array with N
or less elements.
let bytes: Bytes<3> = Bytes::from(&[0, 1, 2]);
let shorter_bytes: Bytes<3> = Bytes::from(&[0, 1]);
Overlong input data causes a compiler error:
ⓘ
let bytes: Bytes<3> = Bytes::from(&[0, 1, 2, 3]); // does not compile
Source§impl<const N: usize, LenT: LenType> From<[u8; N]> for Bytes<N, LenT>
Construct a Bytes<N>
instance from an array with N
elements.
impl<const N: usize, LenT: LenType> From<[u8; N]> for Bytes<N, LenT>
Construct a Bytes<N>
instance from an array with N
elements.
Currently, the array is copied, but a more efficient implementation could be used in the future.
let bytes: Bytes<3> = Bytes::from([0, 1, 2]);
Length mismatches cause a compiler error:
ⓘ
let bytes: Bytes<3> = Bytes::from([0, 1]); // does not compile
ⓘ
let bytes: Bytes<3> = Bytes::from([0, 1, 2, 3]); // does not compile