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>
impl<R> BufReadBacker<R>
source§impl<R: ReadBack> BufReadBacker<R>
impl<R: ReadBack> BufReadBacker<R>
pub fn new(inner: R) -> Self
pub fn with_capacity(capacity: usize, inner: R) -> Self
Trait Implementations§
source§impl<R: ReadBack> BufReadBack for BufReadBacker<R>
impl<R: ReadBack> BufReadBack for BufReadBacker<R>
source§fn read_back_fill_buf(&mut self) -> Result<&[u8]>
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)
fn read_back_consume(&mut self, amt: usize)
source§fn read_back_has_data_left(&mut self) -> Result<bool>
fn read_back_has_data_left(&mut self) -> Result<bool>
source§fn read_back_until(&mut self, delim: u8, buf: &mut Vec<u8>) -> Result<usize>
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 moresource§fn read_back_skip_until(&mut self, delim: u8) -> Result<usize>
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>
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 moresource§fn read_back_split(self, delim: u8) -> ReadBackSplit<Self> ⓘwhere
Self: Sized,
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,
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>
impl<R: Debug> Debug for BufReadBacker<R>
source§impl<R: ReadBack> ReadBack for BufReadBacker<R>
impl<R: ReadBack> ReadBack for BufReadBacker<R>
source§fn read_back(&mut self, buf: &mut [u8]) -> Result<usize>
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>
fn read_back_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize>
source§fn read_back_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize>
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 moresource§fn read_back_to_string(&mut self, buf: &mut String) -> Result<usize>
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 moresource§fn read_back_exact(&mut self, buf: &mut [u8]) -> Result<()>
fn read_back_exact(&mut self, buf: &mut [u8]) -> Result<()>
Read back the exact number of bytes required to fill
buf. Read moresource§fn read_back_bytes(self) -> ReadBackBytes<Self> ⓘwhere
Self: Sized,
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 moresource§fn read_back_chain<R: ReadBack>(self, next: R) -> ReadBackChain<Self, R>where
Self: Sized,
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
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more