pub trait CollectionBytes: CollectionBase {
// Required methods
fn byte_len(&self) -> usize;
fn item_byte_len(item: &Self::Item) -> usize;
}Expand description
Trait for contiguous byte collections.
It is implemented for UTF-8 strings and byte buffers, but not for general collections whose items happen to be bytes.
ⓘ
use collections::CollectionBytes;
fn bytes<C: CollectionBytes>(collection: &C) -> usize {
collection.byte_len()
}
let values = vec![1_u32, 2];
bytes(&values);Required Methods§
Sourcefn byte_len(&self) -> usize
fn byte_len(&self) -> usize
Returns the number of bytes stored in the collection. This is O(1).
Sourcefn item_byte_len(item: &Self::Item) -> usize
fn item_byte_len(item: &Self::Item) -> usize
Returns the number of bytes added by pushing item.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementations on Foreign Types§
Source§impl CollectionBytes for AsciiString
Available on crate feature ascii only.
impl CollectionBytes for AsciiString
Available on crate feature
ascii only.Source§impl CollectionBytes for String
Available on crate feature alloc only.
impl CollectionBytes for String
Available on crate feature
alloc only.Source§impl<LenT: LenType, const N: usize> CollectionBytes for String<N, LenT>
Available on crate feature heapless only.
impl<LenT: LenType, const N: usize> CollectionBytes for String<N, LenT>
Available on crate feature
heapless only.Source§impl<LenT: LenType, const N: usize> CollectionBytes for Vec<u8, N, LenT>
Available on crate feature heapless only.
impl<LenT: LenType, const N: usize> CollectionBytes for Vec<u8, N, LenT>
Available on crate feature
heapless only.