Skip to main content

BufRead

Trait BufRead 

Source
pub trait BufRead: Read {
    // Required methods
    fn fill_buf(&mut self) -> Result<&[u8], IoError>;
    fn consume(&mut self, amount: usize);

    // Provided methods
    fn has_data_left(&mut self) -> Result<bool, IoError> { ... }
    fn skip_until(&mut self, byte: u8) -> Result<usize, IoError> { ... }
    fn read_until(
        &mut self,
        byte: u8,
        buf: &mut Vec<u8>,
    ) -> Result<usize, IoError> { ... }
    fn read_line(&mut self, buf: &mut String) -> Result<usize, IoError> { ... }
    fn split(self, byte: u8) -> Split<Self> 
       where Self: Sized { ... }
    fn lines(self) -> Lines<Self> 
       where Self: Sized { ... }
}
Expand description

A BufRead is a type of Reader which has an internal buffer, allowing it to perform extra ways of reading.

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

Required Methods§

Source

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

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

Source

fn consume(&mut self, amount: 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.

Provided Methods§

Source

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

Checks if there is any data left to be read.

Source

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

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

Source

fn read_until(&mut self, byte: u8, buf: &mut Vec<u8>) -> Result<usize, IoError>

Available on crate feature alloc only.

Read all bytes into buf until the delimiter byte or EOF is reached.

Source

fn read_line(&mut self, buf: &mut String) -> Result<usize, IoError>

Available on crate feature alloc only.

Read all bytes until a newline (the 0xA byte) is reached, and append them to the provided String buffer.

Source

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

Available on crate feature alloc only.

Returns an iterator over the contents of this reader split on the byte byte.

Source

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

Available on crate feature alloc only.

Returns an iterator over the lines of this reader.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl BufRead for &[u8]

Source§

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

Source§

fn consume(&mut self, amt: usize)

Source§

impl BufRead for VecDeque<u8>

Available on crate feature alloc only.
Source§

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

Returns the contents of the “front” slice as returned by as_slices. If the contained byte slices of the VecDeque are discontiguous, multiple calls to fill_buf will be needed to read the entire content.

Source§

fn consume(&mut self, amt: usize)

Source§

impl<B> BufRead for &mut B
where B: BufRead + ?Sized,

Source§

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

Source§

fn consume(&mut self, amt: usize)

Source§

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

Source§

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

Source§

fn read_until(&mut self, byte: u8, buf: &mut Vec<u8>) -> Result<usize, IoError>

Available on crate feature alloc only.
Source§

fn read_line(&mut self, buf: &mut String) -> Result<usize, IoError>

Available on crate feature alloc only.
Source§

impl<B> BufRead for Box<B>
where B: BufRead + ?Sized,

Available on crate feature alloc only.
Source§

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

Source§

fn consume(&mut self, amt: usize)

Source§

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

Source§

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

Source§

fn read_until(&mut self, byte: u8, buf: &mut Vec<u8>) -> Result<usize, IoError>

Source§

fn read_line(&mut self, buf: &mut String) -> Result<usize, IoError>

Implementors§

Source§

impl BufRead for Empty

Source§

impl BufRead for StdinLock<'_>

Source§

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

Source§

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

Source§

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

Source§

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