Struct buffered_reader::Adapter
source · pub struct Adapter<T: BufferedReader<B>, B: Debug + Send + Sync, C: Debug + Sync + Send> { /* private fields */ }
Expand description
Changes the cookie type without introducing any buffering.
If you have a b: BufferedReader<B>
but need a c: BufferedReader<C>
, then one way to do that is to use let c = Generic::with_cookie(b, _)
, but that introduces buffering. This
Adapter
also changes cookie types, but does no buffering of its
own.
Implementations§
source§impl<T: BufferedReader<B>, B: Debug + Send + Sync, C: Debug + Sync + Send> Adapter<T, B, C>
impl<T: BufferedReader<B>, B: Debug + Send + Sync, C: Debug + Sync + Send> Adapter<T, B, C>
Like Self::new
, but sets a cookie.
The cookie can be retrieved using the BufferedReader::cookie_ref
and
BufferedReader::cookie_mut
methods, and set using the BufferedReader::cookie_set
method.
Trait Implementations§
source§impl<T: BufferedReader<B>, B: Debug + Send + Sync, C: Debug + Sync + Send> BufferedReader<C> for Adapter<T, B, C>
impl<T: BufferedReader<B>, B: Debug + Send + Sync, C: Debug + Sync + Send> BufferedReader<C> for Adapter<T, B, C>
source§fn data(&mut self, amount: usize) -> Result<&[u8], Error>
fn data(&mut self, amount: usize) -> Result<&[u8], Error>
Ensures that the internal buffer has at least
amount
bytes
of data, and returns it. Read moresource§fn data_consume_hard(&mut self, amount: usize) -> Result<&[u8], Error>
fn data_consume_hard(&mut self, amount: usize) -> Result<&[u8], Error>
A convenience function that effectively combines
BufferedReader::data_hard
and BufferedReader::consume
. Read moresource§fn consummated(&mut self) -> bool
fn consummated(&mut self) -> bool
Checks whether this reader is consummated. Read more
source§fn get_mut(&mut self) -> Option<&mut dyn BufferedReader<C>>
fn get_mut(&mut self) -> Option<&mut dyn BufferedReader<C>>
Returns a mutable reference to the inner
BufferedReader
, if
any. Read moresource§fn get_ref(&self) -> Option<&dyn BufferedReader<C>>
fn get_ref(&self) -> Option<&dyn BufferedReader<C>>
Returns a reference to the inner
BufferedReader
, if any.source§fn into_inner<'b>(self: Box<Self>) -> Option<Box<dyn BufferedReader<C> + 'b>>where
Self: 'b,
fn into_inner<'b>(self: Box<Self>) -> Option<Box<dyn BufferedReader<C> + 'b>>where
Self: 'b,
Returns the underlying reader, if any. Read more
Sets the
BufferedReader
’s cookie and returns the old value.Returns a reference to the
BufferedReader
’s cookie.Returns a mutable reference to the
BufferedReader
’s cookie.source§fn data_hard(&mut self, amount: usize) -> Result<&[u8], Error>
fn data_hard(&mut self, amount: usize) -> Result<&[u8], Error>
Like
BufferedReader::data
, but returns an error if there is not at least
amount
bytes available. Read moresource§fn data_eof(&mut self) -> Result<&[u8], Error>
fn data_eof(&mut self) -> Result<&[u8], Error>
Returns all of the data until EOF. Like
BufferedReader::data
, this does not
actually consume the data that is read. Read moresource§fn read_be_u16(&mut self) -> Result<u16, Error>
fn read_be_u16(&mut self) -> Result<u16, Error>
A convenience function for reading a 16-bit unsigned integer
in big endian format.
source§fn read_be_u32(&mut self) -> Result<u32, Error>
fn read_be_u32(&mut self) -> Result<u32, Error>
A convenience function for reading a 32-bit unsigned integer
in big endian format.
source§fn read_to(&mut self, terminal: u8) -> Result<&[u8], Error>
fn read_to(&mut self, terminal: u8) -> Result<&[u8], Error>
Reads until either
terminal
is encountered or EOF. Read moresource§fn drop_until(&mut self, terminals: &[u8]) -> Result<usize, Error>
fn drop_until(&mut self, terminals: &[u8]) -> Result<usize, Error>
Discards the input until one of the bytes in terminals is
encountered. Read more
source§fn drop_through(
&mut self,
terminals: &[u8],
match_eof: bool
) -> Result<(Option<u8>, usize), Error>
fn drop_through( &mut self, terminals: &[u8], match_eof: bool ) -> Result<(Option<u8>, usize), Error>
Discards the input until one of the bytes in
terminals
is
encountered. Read moresource§fn steal(&mut self, amount: usize) -> Result<Vec<u8>, Error>
fn steal(&mut self, amount: usize) -> Result<Vec<u8>, Error>
Like
BufferedReader::data_consume_hard
, but returns the data in a
caller-owned buffer. Read moresource§fn steal_eof(&mut self) -> Result<Vec<u8>, Error>
fn steal_eof(&mut self) -> Result<Vec<u8>, Error>
Like
BufferedReader::steal
, but instead of stealing a fixed number of
bytes, steals all of the data until the end of file.source§fn drop_eof(&mut self) -> Result<bool, Error>
fn drop_eof(&mut self) -> Result<bool, Error>
Like
BufferedReader::steal_eof
, but instead of returning the data, the
data is discarded. Read moresource§fn copy(&mut self, sink: &mut dyn Write) -> Result<u64>
fn copy(&mut self, sink: &mut dyn Write) -> Result<u64>
Copies data to the given writer returning the copied amount. Read more
source§fn dump(&self, sink: &mut dyn Write) -> Result<()>where
Self: Sized,
fn dump(&self, sink: &mut dyn Write) -> Result<()>where
Self: Sized,
A helpful debugging aid to pretty print a Buffered Reader stack. Read more
source§fn into_boxed<'a>(self) -> Box<dyn BufferedReader<C> + 'a>where
Self: 'a + Sized,
fn into_boxed<'a>(self) -> Box<dyn BufferedReader<C> + 'a>where
Self: 'a + Sized,
Boxes the reader.
source§impl<T: Debug + BufferedReader<B>, B: Debug + Debug + Send + Sync, C: Debug + Debug + Sync + Send> Debug for Adapter<T, B, C>
impl<T: Debug + BufferedReader<B>, B: Debug + Debug + Send + Sync, C: Debug + Debug + Sync + Send> Debug for Adapter<T, B, C>
source§impl<T: BufferedReader<B>, B: Debug + Send + Sync, C: Debug + Sync + Send> Display for Adapter<T, B, C>
impl<T: BufferedReader<B>, B: Debug + Send + Sync, C: Debug + Sync + Send> Display for Adapter<T, B, C>
source§impl<T: BufferedReader<B>, B: Debug + Send + Sync, C: Debug + Sync + Send> Read for Adapter<T, B, C>
impl<T: BufferedReader<B>, B: Debug + Send + Sync, C: Debug + Sync + Send> Read for Adapter<T, B, C>
source§fn read(&mut self, buf: &mut [u8]) -> Result<usize, Error>
fn read(&mut self, buf: &mut [u8]) -> Result<usize, Error>
Pull some bytes from this source into the specified buffer, returning
how many bytes were read. Read more
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>
Like
read
, except that it reads into a slice of buffers. Read moresource§fn is_read_vectored(&self) -> bool
fn is_read_vectored(&self) -> bool
🔬This is a nightly-only experimental API. (
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>
Read all bytes until EOF in this source, placing them into
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>
Read all bytes until EOF in this source, appending them to
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>
Read the exact number of bytes required to fill
buf
. Read moresource§fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>
fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>
🔬This is a nightly-only experimental API. (
read_buf
)Pull some bytes from this source into the specified buffer. Read more
source§fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>
fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>
🔬This is a nightly-only experimental API. (
read_buf
)Read the exact number of bytes required to fill
cursor
. Read more1.0.0 · source§fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
Creates a “by reference” adaptor for this instance of
Read
. Read moreAuto Trait Implementations§
impl<T, B, C> Freeze for Adapter<T, B, C>
impl<T, B, C> RefUnwindSafe for Adapter<T, B, C>
impl<T, B, C> Send for Adapter<T, B, C>
impl<T, B, C> Sync for Adapter<T, B, C>
impl<T, B, C> Unpin for Adapter<T, B, C>
impl<T, B, C> UnwindSafe for Adapter<T, B, C>
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