Struct markable_reader::MarkableReader
source · pub struct MarkableReader<R> { /* private fields */ }
Expand description
Reads bytes from the inner source with the additional ability
to mark
a stream at a point that can be returned to later
using the a call to reset()
. Whlie the stream is marked all
subsequent reads are returned as usual, but are also buffered,
which is what allows for returning to a previous part of the the stream.
If the inner stream should also be buffered, use BufferedMarkableStream
,
which may offer a slight optimization over passing a std::io::BufReader
as the inner reader to this stream.
Implementations§
source§impl<R> MarkableReader<R>where
R: Read,
impl<R> MarkableReader<R>where
R: Read,
sourcepub fn new(inner: R) -> MarkableReader<R> ⓘ
pub fn new(inner: R) -> MarkableReader<R> ⓘ
Creates a new reader with an unbounded marked buffer
Example
sourcepub fn new_with_limited_back_buffer(inner: R, limit: usize) -> MarkableReader<R> ⓘ
pub fn new_with_limited_back_buffer(inner: R, limit: usize) -> MarkableReader<R> ⓘ
Creates a new reader with an limited marked buffer
Any reads that exceed the provided limit will result in an std::io::Error(ErrorKind::OutOfMemory)
error
The use of this is very similar to that of the std::io::BufReader
Example
sourcepub fn new_with_capacity_and_limit(
inner: R,
capacity: usize,
limit: usize
) -> MarkableReader<R> ⓘ
pub fn new_with_capacity_and_limit( inner: R, capacity: usize, limit: usize ) -> MarkableReader<R> ⓘ
Creates a new reader using the provided capacities as the initial capacity and limit.
Any reads that exceed the provided limit will result in an std::io::Error(ErrorKind::OutOfMemory)
error
Example
sourcepub fn into_inner(self) -> R
pub fn into_inner(self) -> R
Returns the inner reader. IMPORTANT this will likely result in data loss of whatever data has been read into the buffer
Trait Implementations§
source§impl<R> From<R> for MarkableReader<R>where
R: Read,
impl<R> From<R> for MarkableReader<R>where
R: Read,
source§impl<R> MarkerStream for MarkableReader<R>
impl<R> MarkerStream for MarkableReader<R>
source§fn mark(&mut self) -> usize
fn mark(&mut self) -> usize
Marks the location of the inner stream. From tis point forward reads will be cached. If the stream was marked prior to this call the current buffer will be discarded.
Returns the number of bytes that were discarded as a result of this operation
source§fn reset(&mut self)
fn reset(&mut self)
Resets the stream previously marked position, if it is set. If the reader was not previously marked, this has no affect.
source§fn clear_buffer(&mut self)
fn clear_buffer(&mut self)
source§impl<R> Read for MarkableReader<R>where
R: Read,
impl<R> Read for MarkableReader<R>where
R: Read,
source§fn read(&mut self, buf: &mut [u8]) -> Result<usize>
fn read(&mut self, buf: &mut [u8]) -> Result<usize>
1.36.0 · source§fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
read
, except that it reads into a slice of buffers. Read moresource§fn is_read_vectored(&self) -> bool
fn is_read_vectored(&self) -> bool
can_vector
)1.0.0 · source§fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
buf
. Read more1.0.0 · source§fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
buf
. Read more1.6.0 · source§fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
buf
. Read moresource§fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>
fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>
read_buf
)source§fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>
fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>
read_buf
)cursor
. Read more1.0.0 · source§fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
Read
. Read more