Read

Trait Read 

Source
pub trait Read<'a> {
    type Error: Debug + Display;

    // Required method
    fn read_map<R, F>(&mut self, n: usize, f: F) -> Result<R, Self::Error>
       where F: FnOnce(Bytes<'a, '_>) -> R;

    // Provided method
    fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Self::Error> { ... }
}
Expand description

Interface to read bytes

Required Associated Types§

Required Methods§

Source

fn read_map<R, F>(&mut self, n: usize, f: F) -> Result<R, Self::Error>
where F: FnOnce(Bytes<'a, '_>) -> R,

Reads exactly n bytes and passes them to the given function

An error must be returned if there are fewer than n bytes left.

Provided Methods§

Source

fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Self::Error>

Reads exactly buf.len() bytes and writes them to the supplied buffer

An error must be returned if there are fewer than buf.len() bytes left.

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<'a> Read<'a> for &'a [u8]

Source§

type Error = EndOfInput

Source§

fn read_map<R, F>(&mut self, n: usize, f: F) -> Result<R, Self::Error>
where F: FnOnce(Bytes<'a, '_>) -> R,

Source§

impl<'a, T: Read<'a> + ?Sized> Read<'a> for &mut T

Source§

type Error = <T as Read<'a>>::Error

Source§

fn read_map<R, F>(&mut self, n: usize, f: F) -> Result<R, Self::Error>
where F: FnOnce(Bytes<'a, '_>) -> R,

Source§

fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Self::Error>

Implementors§