Skip to main content

Read

Trait Read 

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

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

A generic trait describing an input stream.

See std::io::Read for more information.

Required Methods§

Source

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

Reads bytes from source into buf.

§Returns

The number of bytes read if successful or an Error if reading fails.

§Errors

If the underlying reader encounters an I/O error.

Provided Methods§

Source

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

Reads bytes from source until buf is full.

§Errors

If the exact number of bytes required to fill buf cannot be read.

Source

fn take(self, limit: u64) -> Take<Self>
where Self: Sized,

Constructs a new adapter which will read at most limit bytes.

Source

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

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.

§Returns

The number of bytes read if successful or an Error if reading fails.

§Errors

If an I/O error occurs while reading from the underlying reader.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl Read for &File

Source§

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

Source§

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

Source§

impl Read for &Stdin

Source§

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

Source§

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

Source§

impl Read for &TcpStream

Source§

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

Source§

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

Source§

impl Read for &UnixStream

Source§

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

Source§

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

Source§

impl Read for &[u8]

Source§

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

Source§

impl Read for Arc<File>

Source§

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

Source§

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

Source§

impl Read for ChildStderr

Source§

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

Source§

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

Source§

impl Read for ChildStdout

Source§

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

Source§

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

Source§

impl Read for Empty

Source§

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

Source§

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

Source§

impl Read for File

Source§

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

Source§

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

Source§

impl Read for Repeat

Source§

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

Source§

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

Source§

impl Read for Stdin

Source§

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

Source§

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

Source§

impl Read for StdinLock<'_>

Source§

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

Source§

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

Source§

impl Read for TcpStream

Source§

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

Source§

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

Source§

impl Read for UnixStream

Source§

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

Source§

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

Source§

impl Read for VecDeque<u8>

Source§

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

Source§

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

Source§

impl<R1: Read, R2: Read> Read for Chain<R1, R2>

Source§

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

Source§

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

Source§

impl<R: Read> Read for Take<R>

Source§

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

Source§

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

Source§

impl<R> Read for BufReader<R>
where R: ?Sized + Read,

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Implementors§

Source§

impl<R: Read> Read for bitcoin_io::Take<R>

Source§

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

Source§

impl<T: Read> Read for FromStd<T>

Source§

impl<T: Read> Read for ToStd<T>