Struct read_collection::BufReadBacker

source ·
pub struct BufReadBacker<R> { /* private fields */ }
Expand description

The BufReadBacker<R> struct adds buffering to any ReadBacker.

It’s basically the same as BufReader just for reading back instead of forward.

§Examples

use std::io::{BufReader, Read};
use std::fs::File;
use read_collection::{BufReadBacker, ReadBack};

fn main() -> std::io::Result<()> {
    let file = File::open("some/path")?;
    let mut reader = BufReader::new(file);

    let mut buffer = Vec::new();
    reader.read(&mut buffer).unwrap();


    // let's read the stuff back in
    let mut buffer2 = Vec::new();
    let mut reader = BufReadBacker::from(reader);
    reader.read_back(&mut buffer2)?;

    assert_eq!(buffer, buffer2);
    Ok(())
}

Implementations§

source§

impl<R> BufReadBacker<R>

source

pub fn get_ref(&self) -> &R

source

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

source

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

source

pub fn capacity(&self) -> usize

source

pub fn into_inner(self) -> R

source

pub fn discard_buffer(&mut self)

source§

impl<R: ReadBack> BufReadBacker<R>

source

pub fn new(inner: R) -> Self

source

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

Trait Implementations§

source§

impl<R: ReadBack> BufReadBack for BufReadBacker<R>

source§

fn read_back_fill_buf(&mut self) -> Result<&[u8]>

Returns the contents of the internal buffer, filling it with more data from the inner reader if it is empty. Read more
source§

fn read_back_consume(&mut self, amt: usize)

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

fn read_back_has_data_left(&mut self) -> Result<bool>

Check if the underlying ReadBack has any data left to be read. Read more
source§

fn read_back_until(&mut self, delim: u8, buf: &mut Vec<u8>) -> Result<usize>

Read all bytes into buf until the delimiter byte or the beginning of the reader is reached. Read more
source§

fn read_back_skip_until(&mut self, delim: u8) -> Result<usize>

Skip all bytes until the delimiter byte or the beginning is reached. Read more
source§

fn read_back_line(&mut self, dest: &mut String) -> Result<usize>

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

fn read_back_split(self, delim: u8) -> ReadBackSplit<Self>
where Self: Sized,

Returns an iterator over the contents of this reader split on the byte byte. Read more
source§

fn read_back_lines(self) -> RevLines<Self>
where Self: Sized,

Returns an iterator over the lines of this reader. Read more
source§

impl<R: Debug> Debug for BufReadBacker<R>

source§

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

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

impl<R: ReadBack> From<BufReader<R>> for BufReadBacker<R>

source§

fn from(value: BufReader<R>) -> Self

Converts to this type from the input type.
source§

impl<R: ReadBack> ReadBack for BufReadBacker<R>

source§

fn read_back(&mut self, buf: &mut [u8]) -> Result<usize>

Pull some bytes from this source into the specified buffer, returning how many bytes were read. Read more
source§

fn read_back_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize>

Like Read::read_vectored but it uses rev_read instead of read.
source§

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

Read all bytes until the start of the source, placing them into buf. Read more
source§

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

Read all bytes until the start of the source, prepending them to buf (since we’re reading back). Read more
source§

fn read_back_exact(&mut self, buf: &mut [u8]) -> Result<()>

Read back the exact number of bytes required to fill buf. Read more
source§

fn read_back_bytes(self) -> ReadBackBytes<Self>
where Self: Sized,

Transforms this ReadBack instance to an Iterator over its bytes. This can be also seen as “read the bytes of the instance in reverse”. Read more
source§

fn read_back_chain<R: ReadBack>(self, next: R) -> ReadBackChain<Self, R>
where Self: Sized,

Creates an adapter which will chain this stream with another. Read more
source§

fn read_back_take(self, limit: u64) -> ReadBackTake<Self>
where Self: Sized,

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

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

§

impl<R> UnwindSafe for BufReadBacker<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<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, U> TryFrom<U> for T
where U: Into<T>,

§

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>,

§

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.