Skip to main content

BufReader

Struct BufReader 

Source
pub struct BufReader<R> { /* private fields */ }
Expand description

A reader with a buffer in front: small reads take from the buffer, which is filled by large reads of the reader. Writes, if the reader is also a writer, go straight through.

Implementations§

Source§

impl<R> BufReader<R>

Source

pub fn new(inner: R) -> Self

A reader with a buffer of 8 KiB in front of inner.

Source

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

A reader with a buffer of capacity bytes in front of inner.

Source

pub fn get_ref(&self) -> &R

The reader inside.

Source

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

The reader inside, to change (reading it directly skips the bytes buffered).

Source

pub fn get_pin_mut(self: Pin<&mut Self>) -> Pin<&mut R>
where R: Unpin,

The reader inside, pinned.

Source

pub fn into_inner(self) -> R

The reader inside, taken back; the bytes buffered are lost.

Source

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

The bytes buffered and not read yet.

Trait Implementations§

Source§

impl<R: AsyncRead + Unpin> AsyncBufRead for BufReader<R>

Source§

fn poll_fill_buf( self: Pin<&mut Self>, cx: &mut Context<'_>, ) -> Poll<Result<&[u8]>>

Attempt to return the contents of the internal buffer, filling it with more data from the inner reader if it is empty. Read more
Source§

fn consume(self: Pin<&mut Self>, amount: usize)

Tells this buffer that amt bytes have been consumed from the buffer, so they should no longer be returned in calls to poll_read. Read more
Source§

impl<R: AsyncRead + Unpin> AsyncRead for BufReader<R>

Source§

fn poll_read( self: Pin<&mut Self>, cx: &mut Context<'_>, out: &mut [u8], ) -> Poll<Result<usize>>

Attempt to read from the AsyncRead into buf. Read more
Source§

fn poll_read_vectored( self: Pin<&mut Self>, cx: &mut Context<'_>, bufs: &mut [IoSliceMut<'_>], ) -> Poll<Result<usize, Error>>

Attempt to read from the AsyncRead into bufs using vectored IO operations. Read more
Source§

impl<R: AsyncRead + AsyncSeek + Unpin> AsyncSeek for BufReader<R>

Source§

fn poll_seek( self: Pin<&mut Self>, cx: &mut Context<'_>, pos: SeekFrom, ) -> Poll<Result<u64>>

Seeks the reader; a seek relative to the current position counts from the position of the next byte read through the buffer. The buffer is emptied.

Source§

impl<R: AsyncWrite + Unpin> AsyncWrite for BufReader<R>

Source§

fn poll_write( self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &[u8], ) -> Poll<Result<usize>>

Attempt to write bytes from buf into the object. Read more
Source§

fn poll_write_vectored( self: Pin<&mut Self>, cx: &mut Context<'_>, bufs: &[IoSlice<'_>], ) -> Poll<Result<usize>>

Attempt to write bytes from bufs into the object using vectored IO operations. Read more
Source§

fn poll_flush(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<()>>

Attempt to flush the object, ensuring that any buffered data reach their destination. Read more
Source§

fn poll_close(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<()>>

Attempt to close the object. Read more
Source§

impl<R: Debug> Debug for BufReader<R>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<R> Freeze for BufReader<R>
where R: Freeze,

§

impl<R> RefUnwindSafe for BufReader<R>
where R: RefUnwindSafe,

§

impl<R> Send for BufReader<R>
where R: Send,

§

impl<R> Sync for BufReader<R>
where R: Sync,

§

impl<R> Unpin for BufReader<R>
where R: Unpin,

§

impl<R> UnsafeUnpin for BufReader<R>
where R: UnsafeUnpin,

§

impl<R> UnwindSafe for BufReader<R>
where R: UnwindSafe,

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<R> AsyncBufReadExt for R
where R: AsyncBufRead + ?Sized,

Source§

fn read_until<'a>( &'a mut self, byte: u8, buf: &'a mut Vec<u8>, ) -> ReadUntil<'a, Self> ⓘ
where Self: Unpin,

Reads up to and including byte (or to the end), appending to buf; answers how many bytes it appended (0 at the end).
Source§

fn read_line<'a>(&'a mut self, buf: &'a mut String) -> ReadLine<'a, Self> ⓘ
where Self: Unpin,

Reads up to and including a newline (or to the end), appending to buf if what it read is UTF-8 (an InvalidData error and buf as it was otherwise); answers how many bytes it appended (0 at the end).
Source§

fn lines(self) -> Lines<Self>
where Self: Sized,

The lines, without their \n or \r\n, one by one through Lines::next_line.
Source§

fn split(self, byte: u8) -> Split<Self>
where Self: Sized,

The segments between bytes, without it, one by one through Split::next_segment.
Source§

fn fill_buf(&mut self) -> FillBuf<'_, Self> ⓘ
where Self: Unpin,

The reader’s buffer, filled if it was empty (empty at the end).
Source§

fn consume(&mut self, amount: usize)
where Self: Unpin,

Marks amount bytes of the buffer read.
Source§

impl<R> AsyncReadExt for R
where R: AsyncRead + ?Sized,

Source§

fn read<'a>(&'a mut self, buf: &'a mut [u8]) -> Read<'a, Self> ⓘ
where Self: Unpin,

Reads some bytes into buf, answering how many (0 at the end).
Source§

fn read_buf<'a, 'b>( &'a mut self, buf: &'a mut ReadBuf<'b>, ) -> ReadBufFuture<'a, 'b, Self> ⓘ
where Self: Unpin,

Reads some bytes into the unfilled part of buf and counts them filled, answering how many (0 at the end, or when buf is full).
Source§

fn read_exact<'a>(&'a mut self, buf: &'a mut [u8]) -> ReadExact<'a, Self> ⓘ
where Self: Unpin,

Fills buf exactly, answering its length; an end of the stream first is an UnexpectedEof error.
Source§

fn read_to_end<'a>(&'a mut self, buf: &'a mut Vec<u8>) -> ReadToEnd<'a, Self> ⓘ
where Self: Unpin,

Reads to the end of the stream, appending to buf; answers how many bytes it appended.
Source§

fn read_to_string<'a>( &'a mut self, buf: &'a mut String, ) -> ReadToString<'a, Self> ⓘ
where Self: Unpin,

Reads to the end of the stream, appending to buf if what it read is UTF-8 (an InvalidData error and buf as it was otherwise); answers how many bytes it appended.
Source§

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

A reader that ends after limit bytes of this one.
Source§

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

A reader that reads this one to its end, then next.
Source§

fn read_u8(&mut self) -> ReadNumber<'_, Self, u8, 1> ⓘ
where Self: Unpin,

Reads an unsigned byte (1 bytes, exactly).
Source§

fn read_i8(&mut self) -> ReadNumber<'_, Self, i8, 1> ⓘ
where Self: Unpin,

Reads a signed byte (1 bytes, exactly).
Source§

fn read_u16(&mut self) -> ReadNumber<'_, Self, u16, 2> ⓘ
where Self: Unpin,

Reads a big-endian u16 (2 bytes, exactly).
Source§

fn read_u16_le(&mut self) -> ReadNumber<'_, Self, u16, 2> ⓘ
where Self: Unpin,

Reads a little-endian u16 (2 bytes, exactly).
Source§

fn read_i16(&mut self) -> ReadNumber<'_, Self, i16, 2> ⓘ
where Self: Unpin,

Reads a big-endian i16 (2 bytes, exactly).
Source§

fn read_i16_le(&mut self) -> ReadNumber<'_, Self, i16, 2> ⓘ
where Self: Unpin,

Reads a little-endian i16 (2 bytes, exactly).
Source§

fn read_u32(&mut self) -> ReadNumber<'_, Self, u32, 4> ⓘ
where Self: Unpin,

Reads a big-endian u32 (4 bytes, exactly).
Source§

fn read_u32_le(&mut self) -> ReadNumber<'_, Self, u32, 4> ⓘ
where Self: Unpin,

Reads a little-endian u32 (4 bytes, exactly).
Source§

fn read_i32(&mut self) -> ReadNumber<'_, Self, i32, 4> ⓘ
where Self: Unpin,

Reads a big-endian i32 (4 bytes, exactly).
Source§

fn read_i32_le(&mut self) -> ReadNumber<'_, Self, i32, 4> ⓘ
where Self: Unpin,

Reads a little-endian i32 (4 bytes, exactly).
Source§

fn read_u64(&mut self) -> ReadNumber<'_, Self, u64, 8> ⓘ
where Self: Unpin,

Reads a big-endian u64 (8 bytes, exactly).
Source§

fn read_u64_le(&mut self) -> ReadNumber<'_, Self, u64, 8> ⓘ
where Self: Unpin,

Reads a little-endian u64 (8 bytes, exactly).
Source§

fn read_i64(&mut self) -> ReadNumber<'_, Self, i64, 8> ⓘ
where Self: Unpin,

Reads a big-endian i64 (8 bytes, exactly).
Source§

fn read_i64_le(&mut self) -> ReadNumber<'_, Self, i64, 8> ⓘ
where Self: Unpin,

Reads a little-endian i64 (8 bytes, exactly).
Source§

fn read_u128(&mut self) -> ReadNumber<'_, Self, u128, 16> ⓘ
where Self: Unpin,

Reads a big-endian u128 (16 bytes, exactly).
Source§

fn read_u128_le(&mut self) -> ReadNumber<'_, Self, u128, 16> ⓘ
where Self: Unpin,

Reads a little-endian u128 (16 bytes, exactly).
Source§

fn read_i128(&mut self) -> ReadNumber<'_, Self, i128, 16> ⓘ
where Self: Unpin,

Reads a big-endian i128 (16 bytes, exactly).
Source§

fn read_i128_le(&mut self) -> ReadNumber<'_, Self, i128, 16> ⓘ
where Self: Unpin,

Reads a little-endian i128 (16 bytes, exactly).
Source§

fn read_f32(&mut self) -> ReadNumber<'_, Self, f32, 4> ⓘ
where Self: Unpin,

Reads a big-endian f32 (4 bytes, exactly).
Source§

fn read_f32_le(&mut self) -> ReadNumber<'_, Self, f32, 4> ⓘ
where Self: Unpin,

Reads a little-endian f32 (4 bytes, exactly).
Source§

fn read_f64(&mut self) -> ReadNumber<'_, Self, f64, 8> ⓘ
where Self: Unpin,

Reads a big-endian f64 (8 bytes, exactly).
Source§

fn read_f64_le(&mut self) -> ReadNumber<'_, Self, f64, 8> ⓘ
where Self: Unpin,

Reads a little-endian f64 (8 bytes, exactly).
Source§

impl<S> AsyncSeekExt for S
where S: AsyncSeek + ?Sized,

Source§

fn seek(&mut self, pos: SeekFrom) -> Seek<'_, Self> ⓘ
where Self: Unpin,

Moves the stream’s position, answering the new one from the start.
Source§

fn rewind(&mut self) -> Seek<'_, Self> ⓘ
where Self: Unpin,

Moves the stream’s position to the start.
Source§

fn stream_position(&mut self) -> Seek<'_, Self> ⓘ
where Self: Unpin,

The stream’s position from the start.
Source§

impl<W> AsyncWriteExt for W
where W: AsyncWrite + ?Sized,

Source§

fn write<'a>(&'a mut self, buf: &'a [u8]) -> Write<'a, Self> ⓘ
where Self: Unpin,

Writes some of buf, answering how many bytes.
Source§

fn write_vectored<'a, 'b>( &'a mut self, bufs: &'a [IoSlice<'b>], ) -> WriteVectored<'a, 'b, Self> ⓘ
where Self: Unpin,

Writes some of the slices bufs, in order, answering how many bytes.
Source§

fn write_all<'a>(&'a mut self, buf: &'a [u8]) -> WriteAll<'a, Self> ⓘ
where Self: Unpin,

Writes all of buf; a writer that takes no more bytes is a WriteZero error.
Source§

fn flush(&mut self) -> Flush<'_, Self> ⓘ
where Self: Unpin,

Writes out what the writer holds back, down to its destination.
Source§

fn shutdown(&mut self) -> Shutdown<'_, Self> ⓘ
where Self: Unpin,

Flushes and closes the writing side (poll_close): a socket sends its end of stream, a pipe’s reader sees its end.
Source§

fn write_u8(&mut self, n: u8) -> WriteNumber<'_, Self, { _ }> ⓘ
where Self: Unpin,

Writes an unsigned byte, all of its bytes.
Source§

fn write_i8(&mut self, n: i8) -> WriteNumber<'_, Self, { _ }> ⓘ
where Self: Unpin,

Writes a signed byte, all of its bytes.
Source§

fn write_u16(&mut self, n: u16) -> WriteNumber<'_, Self, { _ }> ⓘ
where Self: Unpin,

Writes a big-endian u16, all of its bytes.
Source§

fn write_u16_le(&mut self, n: u16) -> WriteNumber<'_, Self, { _ }> ⓘ
where Self: Unpin,

Writes a little-endian u16, all of its bytes.
Source§

fn write_i16(&mut self, n: i16) -> WriteNumber<'_, Self, { _ }> ⓘ
where Self: Unpin,

Writes a big-endian i16, all of its bytes.
Source§

fn write_i16_le(&mut self, n: i16) -> WriteNumber<'_, Self, { _ }> ⓘ
where Self: Unpin,

Writes a little-endian i16, all of its bytes.
Source§

fn write_u32(&mut self, n: u32) -> WriteNumber<'_, Self, { _ }> ⓘ
where Self: Unpin,

Writes a big-endian u32, all of its bytes.
Source§

fn write_u32_le(&mut self, n: u32) -> WriteNumber<'_, Self, { _ }> ⓘ
where Self: Unpin,

Writes a little-endian u32, all of its bytes.
Source§

fn write_i32(&mut self, n: i32) -> WriteNumber<'_, Self, { _ }> ⓘ
where Self: Unpin,

Writes a big-endian i32, all of its bytes.
Source§

fn write_i32_le(&mut self, n: i32) -> WriteNumber<'_, Self, { _ }> ⓘ
where Self: Unpin,

Writes a little-endian i32, all of its bytes.
Source§

fn write_u64(&mut self, n: u64) -> WriteNumber<'_, Self, { _ }> ⓘ
where Self: Unpin,

Writes a big-endian u64, all of its bytes.
Source§

fn write_u64_le(&mut self, n: u64) -> WriteNumber<'_, Self, { _ }> ⓘ
where Self: Unpin,

Writes a little-endian u64, all of its bytes.
Source§

fn write_i64(&mut self, n: i64) -> WriteNumber<'_, Self, { _ }> ⓘ
where Self: Unpin,

Writes a big-endian i64, all of its bytes.
Source§

fn write_i64_le(&mut self, n: i64) -> WriteNumber<'_, Self, { _ }> ⓘ
where Self: Unpin,

Writes a little-endian i64, all of its bytes.
Source§

fn write_u128(&mut self, n: u128) -> WriteNumber<'_, Self, { _ }> ⓘ
where Self: Unpin,

Writes a big-endian u128, all of its bytes.
Source§

fn write_u128_le(&mut self, n: u128) -> WriteNumber<'_, Self, { _ }> ⓘ
where Self: Unpin,

Writes a little-endian u128, all of its bytes.
Source§

fn write_i128(&mut self, n: i128) -> WriteNumber<'_, Self, { _ }> ⓘ
where Self: Unpin,

Writes a big-endian i128, all of its bytes.
Source§

fn write_i128_le(&mut self, n: i128) -> WriteNumber<'_, Self, { _ }> ⓘ
where Self: Unpin,

Writes a little-endian i128, all of its bytes.
Source§

fn write_f32(&mut self, n: f32) -> WriteNumber<'_, Self, { _ }> ⓘ
where Self: Unpin,

Writes a big-endian f32, all of its bytes.
Source§

fn write_f32_le(&mut self, n: f32) -> WriteNumber<'_, Self, { _ }> ⓘ
where Self: Unpin,

Writes a little-endian f32, all of its bytes.
Source§

fn write_f64(&mut self, n: f64) -> WriteNumber<'_, Self, { _ }> ⓘ
where Self: Unpin,

Writes a big-endian f64, all of its bytes.
Source§

fn write_f64_le(&mut self, n: f64) -> WriteNumber<'_, Self, { _ }> ⓘ
where Self: Unpin,

Writes a little-endian f64, all of its bytes.
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> MaybeSend for T
where T: Send + ?Sized,

Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.