pub struct BufReader<T> { /* private fields */ }
std
only.Expand description
A wrapper to add buffering to a read stream.
Unlike std::io::BufReader
, this wrapper does not invalidate the read
buffer every time a Seek
method is called. It also caches
the underlying stream position to avoid unnecessary system calls.
Limitations
Reading or seeking the wrapped stream object directly will cause an
inconsistency in the internal state of the BufReader
. Calling
BufReader::seek_invalidate
will clear the read buffer and reset the
internal state to be consistent with the wrapped stream.
Implementations§
source§impl<T> BufReader<T>
impl<T> BufReader<T>
sourcepub fn capacity(&self) -> usize
pub fn capacity(&self) -> usize
Returns the number of bytes the internal buffer can hold at once.
sourcepub fn get_mut(&mut self) -> &mut T
pub fn get_mut(&mut self) -> &mut T
Gets a mutable reference to the underlying reader.
It is inadvisable to directly read from the underlying reader as it will, at the least, break the cached position information.
sourcepub fn into_inner(self) -> T
pub fn into_inner(self) -> T
Unwraps this BufReader<T>
, returning the underlying reader.
Note that any leftover data in the internal buffer is lost. Therefore, a following read from the underlying reader may lead to data loss.
Trait Implementations§
source§impl<T: Read> BufRead for BufReader<T>
impl<T: Read> BufRead for BufReader<T>
source§fn fill_buf(&mut self) -> Result<&[u8]>
fn fill_buf(&mut self) -> Result<&[u8]>
source§fn consume(&mut self, amt: usize)
fn consume(&mut self, amt: usize)
amt
bytes have been consumed from the buffer,
so they should no longer be returned in calls to read
. Read moresource§fn has_data_left(&mut self) -> Result<bool, Error>
fn has_data_left(&mut self) -> Result<bool, Error>
buf_read_has_data_left
)Read
has any data left to be read. Read more1.0.0 · source§fn read_until(
&mut self,
byte: u8,
buf: &mut Vec<u8, Global>
) -> Result<usize, Error>
fn read_until( &mut self, byte: u8, buf: &mut Vec<u8, Global> ) -> Result<usize, Error>
1.0.0 · source§fn read_line(&mut self, buf: &mut String) -> Result<usize, Error>
fn read_line(&mut self, buf: &mut String) -> Result<usize, Error>
0xA
byte) is reached, and append
them to the provided String
buffer. Read moresource§impl<T: Read> Read for BufReader<T>
impl<T: Read> Read for BufReader<T>
source§fn read(&mut self, buf: &mut [u8]) -> Result<usize>
fn read(&mut self, buf: &mut [u8]) -> Result<usize>
source§fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize>
fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize>
read
, except that it reads into a slice of buffers. Read moresource§fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize>
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize>
buf
. Read moresource§fn read_to_string(&mut self, buf: &mut String) -> Result<usize>
fn read_to_string(&mut self, buf: &mut String) -> Result<usize>
buf
. Read moresource§fn read_exact(&mut self, buf: &mut [u8]) -> Result<()>
fn read_exact(&mut self, buf: &mut [u8]) -> Result<()>
buf
. Read moresource§fn is_read_vectored(&self) -> bool
fn is_read_vectored(&self) -> bool
can_vector
)source§fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>
fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>
read_buf
)source§fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>
fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>
read_buf
)cursor
. Read more1.0.0 · source§fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
fn by_ref(&mut self) -> &mut Selfwhere Self: Sized,
Read
. Read moresource§impl<T: Seek> Seek for BufReader<T>
impl<T: Seek> Seek for BufReader<T>
source§fn seek(&mut self, pos: SeekFrom) -> Result<u64>
fn seek(&mut self, pos: SeekFrom) -> Result<u64>
source§fn stream_position(&mut self) -> Result<u64>
fn stream_position(&mut self) -> Result<u64>
Auto Trait Implementations§
impl<T> RefUnwindSafe for BufReader<T>where T: RefUnwindSafe,
impl<T> Send for BufReader<T>where T: Send,
impl<T> Sync for BufReader<T>where T: Sync,
impl<T> Unpin for BufReader<T>where T: Unpin,
impl<T> UnwindSafe for BufReader<T>where T: UnwindSafe,
Blanket Implementations§
source§impl<R> BinReaderExt for Rwhere
R: Read + Seek,
impl<R> BinReaderExt for Rwhere R: Read + Seek,
source§fn read_type<'a, T>(&mut self, endian: Endian) -> BinResult<T>where
T: BinRead,
T::Args<'a>: Required + Clone,
fn read_type<'a, T>(&mut self, endian: Endian) -> BinResult<T>where T: BinRead, T::Args<'a>: Required + Clone,
T
from the reader with the given byte order. Read moresource§fn read_be<'a, T>(&mut self) -> BinResult<T>where
T: BinRead,
T::Args<'a>: Required + Clone,
fn read_be<'a, T>(&mut self) -> BinResult<T>where T: BinRead, T::Args<'a>: Required + Clone,
T
from the reader assuming big-endian byte order. Read moresource§fn read_le<'a, T>(&mut self) -> BinResult<T>where
T: BinRead,
T::Args<'a>: Required + Clone,
fn read_le<'a, T>(&mut self) -> BinResult<T>where T: BinRead, T::Args<'a>: Required + Clone,
T
from the reader assuming little-endian byte order. Read moresource§fn read_ne<'a, T>(&mut self) -> BinResult<T>where
T: BinRead,
T::Args<'a>: Required + Clone,
fn read_ne<'a, T>(&mut self) -> BinResult<T>where T: BinRead, T::Args<'a>: Required + Clone,
T
from the reader assuming native-endian byte order. Read moresource§fn read_type_args<'a, T>(
&mut self,
endian: Endian,
args: T::Args<'a>
) -> BinResult<T>where
T: BinRead,
T::Args<'a>: Clone,
fn read_type_args<'a, T>( &mut self, endian: Endian, args: T::Args<'a> ) -> BinResult<T>where T: BinRead, T::Args<'a>: Clone,
T
from the reader with the given byte order and arguments. Read moresource§fn read_be_args<'a, T>(&mut self, args: T::Args<'a>) -> BinResult<T>where
T: BinRead,
T::Args<'a>: Clone,
fn read_be_args<'a, T>(&mut self, args: T::Args<'a>) -> BinResult<T>where T: BinRead, T::Args<'a>: Clone,
T
from the reader, assuming big-endian byte order, using the
given arguments. Read more