Skip to main content

CollectionBytes

Trait CollectionBytes 

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

Source

fn byte_len(&self) -> usize

Returns the number of bytes stored in the collection. This is O(1).

Source

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

fn byte_len(&self) -> usize

Source§

fn item_byte_len(_item: &Self::Item) -> usize

Source§

impl CollectionBytes for String

Available on crate feature alloc only.
Source§

fn byte_len(&self) -> usize

Source§

fn item_byte_len(item: &Self::Item) -> usize

Source§

impl<A: Allocator> CollectionBytes for Vec<u8, A>

Available on crate feature alloc only.
Source§

fn byte_len(&self) -> usize

Source§

fn item_byte_len(_item: &Self::Item) -> usize

Source§

impl<LenT: LenType, const N: usize> CollectionBytes for String<N, LenT>

Available on crate feature heapless only.
Source§

fn byte_len(&self) -> usize

Source§

fn item_byte_len(item: &Self::Item) -> usize

Source§

impl<LenT: LenType, const N: usize> CollectionBytes for Vec<u8, N, LenT>

Available on crate feature heapless only.
Source§

fn byte_len(&self) -> usize

Source§

fn item_byte_len(_item: &Self::Item) -> usize

Implementors§