Trait Read

Source
pub trait Read {
    // Required method
    fn read(&mut self, buf: &mut [u8]) -> Result<usize, Error>;

    // Provided methods
    fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error> { ... }
    fn take(&mut self, limit: u64) -> Take<'_, Self> { ... }
    fn read_to_limit(
        &mut self,
        buf: &mut Vec<u8>,
        limit: u64,
    ) -> Result<usize, Error> { ... }
}
Expand description

A generic trait describing an input stream. See [std::io::Read] for more info.

Required Methods§

Source

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

Reads bytes from source into buf.

Provided Methods§

Source

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

Reads bytes from source until buf is full.

Source

fn take(&mut self, limit: u64) -> Take<'_, Self>

Creates an adapter which will read at most limit bytes.

Source

fn read_to_limit( &mut self, buf: &mut Vec<u8>, limit: u64, ) -> Result<usize, Error>

Available on crate feature alloc only.

Attempts to read up to limit bytes from the reader, allocating space in buf as needed.

limit is used to prevent a denial of service attack vector since an unbounded reader will exhaust all memory.

Similar to std::io::Read::read_to_end but with the DOS protection.

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

Source§

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

Implementors§

Source§

impl<'a, R> Read for Take<'a, R>
where R: Read + ?Sized,

Source§

impl<'a, R: Read> Read for FixedLengthReader<'a, R>

Source§

impl<'a, R: Read> Read for ReadTrackingReader<'a, R>

Source§

impl<T> Read for bitcoin_io::Cursor<T>
where T: AsRef<[u8]>,

Source§

impl<T: AsRef<[u8]>> Read for lightning::io::Cursor<T>