AsBytes

Trait AsBytes 

Source
pub trait AsBytes {
    // Required methods
    fn as_bytes(&self) -> &[u8] ;
    fn len(&self) -> usize;

    // Provided methods
    fn to_bytes_vec(&self) -> Vec<u8>  { ... }
    fn byte_size(&self) -> usize { ... }
}
Expand description

Trait for borrowing data as byte slices. This trait abstracts the conversion of types that implement Pod (or collections thereof) into their raw byte representation as a slice (&[u8]).

Required Methods§

Source

fn as_bytes(&self) -> &[u8]

Returns the underlying byte slice of the data.

Source

fn len(&self) -> usize

Returns the count of elements contained in the data. For single-element tuples (T,), this is 1. For collections (Vec<T>, &[T], [T; N]), this is the number of T items.

Provided Methods§

Source

fn to_bytes_vec(&self) -> Vec<u8>

Returns an owned vector containing a copy of the bytes of the data. The default implementation clones the bytes from as_bytes().

Source

fn byte_size(&self) -> usize

Returns the size in bytes of the data.

Implementations on Foreign Types§

Source§

impl<T> AsBytes for [T]
where T: Pod,

Implementation for [T] where T is POD.

Source§

fn as_bytes(&self) -> &[u8]

Source§

fn byte_size(&self) -> usize

Source§

fn len(&self) -> usize

Source§

impl<T> AsBytes for (T,)
where T: Pod,

Implementation for single POD types wrapped in a tuple (T,).

Source§

fn as_bytes(&self) -> &[u8]

Source§

fn byte_size(&self) -> usize

Source§

fn len(&self) -> usize

Source§

impl<T> AsBytes for Vec<T>
where T: Pod,

Implementation for Vec where T is POD.

Source§

fn as_bytes(&self) -> &[u8]

Source§

fn byte_size(&self) -> usize

Source§

fn len(&self) -> usize

Source§

impl<T, const N: usize> AsBytes for [T; N]
where T: Pod,

Implementation for [T; N] where T is POD.

Source§

fn as_bytes(&self) -> &[u8]

Source§

fn byte_size(&self) -> usize

Source§

fn len(&self) -> usize

Implementors§