Skip to main content

BufReader

Struct BufReader 

Source
pub struct BufReader<R>
where R: ?Sized,
{ /* private fields */ }
Expand description

The BufReader<R> struct adds buffering to any reader.

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

Implementations§

Source§

impl<R> BufReader<R>
where R: Read,

Source

pub fn with_capacity(capacity: usize, inner: R) -> BufReader<R>

Creates a new BufReader<R> with the specified buffer capacity.

Source

pub fn new(inner: R) -> BufReader<R>

Creates a new BufReader<R> with a default buffer capacity.

Source§

impl<R> BufReader<R>
where R: ?Sized,

Source

pub fn get_ref(&self) -> &R

Gets a reference to the underlying reader.

It is inadvisable to directly read from the underlying reader.

Source

pub fn get_mut(&mut self) -> &mut R

Gets a mutable reference to the underlying reader.

It is inadvisable to directly read from the underlying reader.

Source

pub fn buffer(&self) -> &[u8]

Returns a reference to the internally buffered data.

Unlike fill_buf, this will not attempt to fill the buffer if it is empty.

Source

pub fn capacity(&self) -> usize

Returns the number of bytes the internal buffer can hold at once.

Source

pub fn into_inner(self) -> R

Unwraps this BufReader<R>, 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.

Source§

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

Source

pub fn peek(&mut self, n: usize) -> Result<&[u8], AxError>

Attempt to look ahead n bytes.

n must be less than or equal to capacity.

The returned slice may be less than n bytes long if end of file is reached.

After calling this method, you may call consume with a value less than or equal to n to advance over some or all of the returned bytes.

Trait Implementations§

Source§

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

Source§

fn fill_buf(&mut self) -> Result<&[u8], AxError>

Returns the contents of the internal buffer, filling it with more data, via Read methods, if empty.
Source§

fn consume(&mut self, amt: usize)

Marks the given amount of additional bytes from the internal buffer as having been read. Subsequent calls to read only return bytes that have not been marked as read.
Source§

fn has_data_left(&mut self) -> Result<bool, AxError>

Checks if there is any data left to be read.
Source§

fn skip_until(&mut self, byte: u8) -> Result<usize, AxError>

Skips all bytes until the delimiter byte or EOF is reached.
Source§

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

Source§

fn fmt(&self, fmt: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

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

Source§

fn remaining(&self) -> usize

Returns the number of bytes between the current position and the end of the buffer.
Source§

fn is_empty(&self) -> bool

Returns true if there are no remaining bytes in the buffer.
Source§

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

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

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

Pull some bytes from this source into the specified buffer. Read more
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_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), AxError>

Reads the exact number of bytes required to fill cursor. Read more
Source§

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

Creates a “by reference” adapter for this instance of Read. Read more
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. Read more
Source§

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

Creates an adapter which will read at most limit bytes from it. Read more
Source§

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

Source§

fn seek(&mut self, pos: SeekFrom) -> Result<u64, AxError>

Seek to an offset, in bytes, in the underlying reader.

The position used for seeking with SeekFrom::Current(_) is the position the underlying reader would be at if the BufReader<R> had no internal buffer.

Seeking always discards the internal buffer, even if the seek position would otherwise fall within it. This guarantees that calling BufReader::into_inner() immediately after a seek yields the underlying reader at the same position.

To seek without discarding the internal buffer, use BufReader::seek_relative.

See Seek for more details.

Note: In the edge case where you’re seeking with SeekFrom::Current(n) where n minus the internal buffer length overflows an i64, two seeks will be performed instead of one. If the second seek returns Err, the underlying reader will be left at the same position it would have if you called seek with SeekFrom::Current(0).

Source§

fn stream_position(&mut self) -> Result<u64, AxError>

Returns the current seek position from the start of the stream.

The value returned is equivalent to self.seek(SeekFrom::Current(0)) but does not flush the internal buffer. Due to this optimization the function does not guarantee that calling .into_inner() immediately afterwards will yield the underlying reader at the same position. Use BufReader::seek instead if you require that guarantee.

§Panics

This function will panic if the position of the inner reader is smaller than the amount of buffered data. That can happen if the inner reader has an incorrect implementation of Seek::stream_position, or if the position has gone out of sync due to calling Seek::seek directly on the underlying reader.

Source§

fn seek_relative(&mut self, offset: i64) -> Result<(), AxError>

Seeks relative to the current position.

If the new position lies within the buffer, the buffer will not be flushed, allowing for more efficient seeks. This method does not return the location of the underlying reader, so the caller must track this information themselves if it is required.

Source§

fn rewind(&mut self) -> Result<(), AxError>

Rewind to the beginning of a stream. Read more
Source§

fn stream_len(&mut self) -> Result<u64, AxError>

Returns the length of this stream (in bytes).

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

§

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

§

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

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IoBufExt for T
where T: Read + IoBuf + ?Sized,

Source§

fn write_to<W>(&mut self, writer: &mut W) -> Result<usize, AxError>
where W: Write + ?Sized,

Reads some bytes from this buffer and writes them into writer.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.