Skip to main content

BytesLike

Trait BytesLike 

Source
pub trait BytesLike<'encoding>: Sized {
    type ExternallyTrackedLength: Sized + Copy;

    // Required methods
    fn len(&self, len: Self::ExternallyTrackedLength) -> usize;
    fn read_bytes(
        &mut self,
        bytes: usize,
    ) -> Result<(Self::ExternallyTrackedLength, Self), EpeeError>;
    fn read_into_slice(&mut self, slice: &mut [u8]) -> Result<(), EpeeError>;

    // Provided methods
    fn read_byte(&mut self) -> Result<u8, EpeeError> { ... }
    fn advance<const N: usize>(&mut self) -> Result<(), EpeeError> { ... }
}
Expand description

An item which is like a &[u8].

Required Associated Types§

Source

type ExternallyTrackedLength: Sized + Copy

The type representing the length of a read BytesLike, if a BytesLike does not inherently know its length.

This should be usize or ().

Required Methods§

Source

fn len(&self, len: Self::ExternallyTrackedLength) -> usize

The length of these bytes.

Source

fn read_bytes( &mut self, bytes: usize, ) -> Result<(Self::ExternallyTrackedLength, Self), EpeeError>

Read a fixed amount of bytes from the container.

This MUST return Ok((len, slice)) where slice is the expected length or Err(_).

Source

fn read_into_slice(&mut self, slice: &mut [u8]) -> Result<(), EpeeError>

Read a fixed amount of bytes from the container into a slice.

Provided Methods§

Source

fn read_byte(&mut self) -> Result<u8, EpeeError>

Read a byte from the container.

Source

fn advance<const N: usize>(&mut self) -> Result<(), EpeeError>

Advance the container by a certain amount of bytes.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl<'encoding> BytesLike<'encoding> for &'encoding [u8]

Source§

type ExternallyTrackedLength = ()

Source§

fn len(&self, (): ()) -> usize

Source§

fn read_bytes( &mut self, bytes: usize, ) -> Result<(Self::ExternallyTrackedLength, Self), EpeeError>

Source§

fn read_into_slice(&mut self, slice: &mut [u8]) -> Result<(), EpeeError>

Implementors§