Skip to main content

Read

Trait Read 

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

    // Provided methods
    fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), AxError> { ... }
    fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), AxError> { ... }
    fn read_buf_exact(
        &mut self,
        cursor: BorrowedCursor<'_>,
    ) -> Result<(), AxError> { ... }
    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, AxError>

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<(), AxError>

Read the exact number of bytes required to fill buf.

Source

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

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<'_>) -> Result<(), AxError>

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 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.

Implementations on Foreign Types§

Source§

impl Read for &[u8]

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

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 ReadFn<R>
where R: FnMut(&mut [u8]) -> Result<usize, AxError>,

Source§

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

Source§

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

Source§

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

Source§

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