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§
Provided Methods§
Sourcefn read_exact(&mut self, buf: &mut [u8]) -> Result<(), IoError>
fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), IoError>
Read the exact number of bytes required to fill buf.
Sourcefn read_buf(&mut self, buf: BorrowedCursor<'_, u8>) -> Result<(), IoError>
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.
Sourcefn read_buf_exact(
&mut self,
cursor: BorrowedCursor<'_, u8>,
) -> Result<(), IoError>
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.
Sourcefn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, IoError>
Available on crate feature alloc only.
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, IoError>
alloc only.Read all bytes until EOF in this source, placing them into buf.
Sourcefn read_to_string(&mut self, buf: &mut String) -> Result<usize, IoError>
Available on crate feature alloc only.
fn read_to_string(&mut self, buf: &mut String) -> Result<usize, IoError>
alloc only.Read all bytes until EOF in this source, appending them to buf.
Sourcefn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
fn by_ref(&mut self) -> &mut Selfwhere
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.
Sourcefn chain<R>(self, next: R) -> Chain<Self, R>
fn chain<R>(self, next: R) -> Chain<Self, R>
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.
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]
impl Read for &[u8]
fn read(&mut self, buf: &mut [u8]) -> Result<usize, IoError>
fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), IoError>
fn read_buf(&mut self, cursor: BorrowedCursor<'_, u8>) -> Result<(), IoError>
fn read_buf_exact( &mut self, cursor: BorrowedCursor<'_, u8>, ) -> Result<(), IoError>
Source§impl Read for VecDeque<u8>
Available on crate feature alloc only.
impl Read for VecDeque<u8>
alloc only.fn read(&mut self, buf: &mut [u8]) -> Result<usize, IoError>
fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), IoError>
fn read_buf(&mut self, cursor: 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>
Source§impl<R> Read for &mut R
impl<R> Read for &mut R
fn read(&mut self, buf: &mut [u8]) -> Result<usize, IoError>
fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), IoError>
fn read_buf(&mut self, cursor: BorrowedCursor<'_, u8>) -> Result<(), IoError>
fn read_buf_exact( &mut self, cursor: BorrowedCursor<'_, u8>, ) -> Result<(), IoError>
Source§impl<R> Read for Box<R>
Available on crate feature alloc only.
impl<R> Read for Box<R>
alloc only.