Bytes

Type Alias Bytes 

Source
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>

Source

pub const fn new() -> Self

Construct a new, empty Bytes<N>.

Source

pub const fn const_capacity(&self) -> usize

Get the capacity of the buffer.

Always equal to the N const generic.

Source

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();
Source

pub fn cast_len_type<NewLenT: LenType>(self) -> Bytes<N, NewLenT>

Trait Implementations§

Source§

impl<const N: usize, LenT: LenType> Clone for Bytes<N, LenT>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<const N: usize, LenT: LenType> Default for Bytes<N, LenT>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

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>,

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.

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§

fn from(data: &[u8; M]) -> Self

Converts to this type from the input type.
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.

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
Source§

fn from(bytes: [u8; N]) -> Self

Converts to this type from the input type.
Source§

impl<const N: usize, LenT: LenType> IntoIterator for Bytes<N, LenT>

Source§

type Item = u8

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<N, LenT>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<const N: usize, LenT: LenType> TryFrom<&[u8]> for Bytes<N, LenT>

Source§

type Error = CapacityError

The type returned in the event of a conversion error.
Source§

fn try_from(value: &[u8]) -> Result<Self, CapacityError>

Performs the conversion.