Skip to main content

Read

Trait Read 

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

    // Provided methods
    fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), IoError> { ... }
    fn read_buf(&mut self, buf: BorrowedCursor<'_, u8>) -> Result<(), IoError> { ... }
    fn read_buf_exact(
        &mut self,
        cursor: BorrowedCursor<'_, u8>,
    ) -> Result<(), IoError> { ... }
    fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, IoError> { ... }
    fn read_to_string(&mut self, buf: &mut String) -> Result<usize, IoError> { ... }
    fn by_ref(&mut self) -> &mut Self
       where Self: Sized { ... }
    fn chain<R>(self, next: R) -> Chain<Self, R>
       where R: Read,
             Self: Sized { ... }
    fn take(self, limit: u64) -> Take<Self>
       where Self: Sized { ... }
}
Expand description

The Read trait allows for reading bytes from a source.

See [std::io::Read] for more details.

Required Methods§

Source

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

Pull some bytes from this source into the specified buffer, returning how many bytes were read.

Provided Methods§

Source

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

Read the exact number of bytes required to fill buf.

Source

fn read_buf(&mut self, buf: BorrowedCursor<'_, u8>) -> Result<(), IoError>

Pull some bytes from this source into the specified buffer.

This method makes it possible to return both data and an error but it is advised against.

Source

fn read_buf_exact( &mut self, cursor: BorrowedCursor<'_, u8>, ) -> Result<(), IoError>

Reads the exact number of bytes required to fill cursor.

If this function returns an error, all bytes read will be appended to cursor.

Source

fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, IoError>

Available on crate feature alloc only.

Read all bytes until EOF in this source, placing them into buf.

Source

fn read_to_string(&mut self, buf: &mut String) -> Result<usize, IoError>

Available on crate feature alloc only.

Read all bytes until EOF in this source, appending them to buf.

Source

fn by_ref(&mut self) -> &mut Self
where Self: Sized,

Creates a “by reference” adapter for this instance of Read.

The returned adapter also implements Read and will simply borrow this current reader.

Source

fn chain<R>(self, next: R) -> Chain<Self, R>
where R: Read, Self: Sized,

Creates an adapter which will chain this stream with another.

The returned Read instance will first read all bytes from this object until EOF is encountered. Afterwards the output is equivalent to the output of next.

Source

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

Creates an adapter which will read at most limit bytes from it.

This function returns a new instance of Read which will read at most limit bytes, after which it will always return EOF (Ok(0)). Any read errors will not count towards the number of bytes read and future calls to read() may succeed.

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

Source§

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

Source§

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

Source§

fn read_buf(&mut self, cursor: BorrowedCursor<'_, u8>) -> Result<(), IoError>

Source§

fn read_buf_exact( &mut self, cursor: BorrowedCursor<'_, u8>, ) -> Result<(), IoError>

Source§

fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, IoError>

Available on crate feature alloc only.
Source§

fn read_to_string(&mut self, buf: &mut String) -> Result<usize, IoError>

Available on crate feature alloc only.
Source§

impl Read for VecDeque<u8>

Available on crate feature alloc only.
Source§

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

Source§

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

Source§

fn read_buf(&mut self, cursor: BorrowedCursor<'_, u8>) -> Result<(), IoError>

Source§

fn read_buf_exact( &mut self, cursor: BorrowedCursor<'_, u8>, ) -> Result<(), IoError>

Source§

fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, IoError>

Source§

fn read_to_string(&mut self, buf: &mut String) -> Result<usize, IoError>

Source§

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

Source§

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

Source§

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

Source§

fn read_buf(&mut self, cursor: BorrowedCursor<'_, u8>) -> Result<(), IoError>

Source§

fn read_buf_exact( &mut self, cursor: BorrowedCursor<'_, u8>, ) -> Result<(), IoError>

Source§

fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, IoError>

Available on crate feature alloc only.
Source§

fn read_to_string(&mut self, buf: &mut String) -> Result<usize, IoError>

Available on crate feature alloc only.
Source§

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

Available on crate feature alloc only.
Source§

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

Source§

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

Source§

fn read_buf(&mut self, cursor: BorrowedCursor<'_, u8>) -> Result<(), IoError>

Source§

fn read_buf_exact( &mut self, cursor: BorrowedCursor<'_, u8>, ) -> Result<(), IoError>

Source§

fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, IoError>

Source§

fn read_to_string(&mut self, buf: &mut String) -> Result<usize, IoError>

Implementors§

Source§

impl Read for Empty

Source§

impl Read for Repeat

Source§

impl Read for Stdin

Source§

impl Read for StdinLock<'_>

Source§

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

Source§

impl<R> Read for ReadFn<R>
where R: FnMut(&mut [u8]) -> Result<usize, IoError>,

Source§

impl<T, U> Read for Chain<T, U>
where T: Read, U: Read,

Source§

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

Source§

impl<T> Read for Take<T>
where T: Read,