pub struct ZCursor<T> {
pub(crate) stream: T,
pub(crate) position: usize,
}Expand description
Wraps an in memory buffer providing it with a Seek method
but works in no_std environments
std::io::Cursor is available in std environments, but we also need support
for no_std environments so this serves as a drop in replacement
Fields§
§stream: T§position: usizeImplementations§
Source§impl<T: AsRef<[u8]>> ZCursor<T>
impl<T: AsRef<[u8]>> ZCursor<T>
Sourcepub fn skip(&mut self, num: usize)
pub fn skip(&mut self, num: usize)
Move forward num bytes from
the current position.
It doesn’t check that position overflowed, new position may point past the internal buffer, all subsequent reads will either return an error or zero depending on the method called
Sourcepub fn rewind(&mut self, num: usize)
pub fn rewind(&mut self, num: usize)
Move back num bytes from the current position
This saturates at zero, it can never be negative or wraparound when the value becomes too small
pub fn split(&self) -> (&[u8], &[u8])
Source§impl<T: AsRef<[u8]>> ZCursor<T>
impl<T: AsRef<[u8]>> ZCursor<T>
pub(crate) fn read_byte_no_error_impl(&mut self) -> u8
pub(crate) fn read_exact_bytes_impl( &mut self, buf: &mut [u8], ) -> Result<(), ZByteIoError>
pub(crate) fn read_const_bytes_impl<const N: usize>( &mut self, buf: &mut [u8; N], ) -> Result<(), ZByteIoError>
pub(crate) fn read_const_bytes_no_error_impl<const N: usize>( &mut self, buf: &mut [u8; N], )
pub(crate) fn read_bytes_impl( &mut self, buf: &mut [u8], ) -> Result<usize, ZByteIoError>
pub(crate) fn peek_bytes_impl( &mut self, buf: &mut [u8], ) -> Result<usize, ZByteIoError>
pub(crate) fn peek_exact_bytes_impl( &mut self, buf: &mut [u8], ) -> Result<(), ZByteIoError>
pub(crate) fn z_seek_impl( &mut self, from: ZSeekFrom, ) -> Result<u64, ZByteIoError>
pub(crate) fn is_eof_impl(&mut self) -> Result<bool, ZByteIoError>
pub(crate) fn z_position_impl(&mut self) -> Result<u64, ZByteIoError>
pub(crate) fn read_remaining_impl( &mut self, sink: &mut Vec<u8>, ) -> Result<usize, ZByteIoError>
Trait Implementations§
Source§impl<T: AsRef<[u8]>> BufRead for ZCursor<T>
impl<T: AsRef<[u8]>> BufRead for ZCursor<T>
Source§fn fill_buf(&mut self) -> Result<&[u8]>
fn fill_buf(&mut self) -> Result<&[u8]>
Returns the contents of the internal buffer, filling it with more data, via
Read methods, if empty. Read moreSource§fn consume(&mut self, amount: usize)
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. Read moreSource§fn has_data_left(&mut self) -> Result<bool, Error>
fn has_data_left(&mut self) -> Result<bool, Error>
🔬This is a nightly-only experimental API. (
buf_read_has_data_left)Checks if there is any data left to be
read. Read more1.83.0 · Source§fn skip_until(&mut self, byte: u8) -> Result<usize, Error>
fn skip_until(&mut self, byte: u8) -> Result<usize, Error>
Skips all bytes until the delimiter
byte or EOF is reached. Read more1.0.0 · Source§fn read_line(&mut self, buf: &mut String) -> Result<usize, Error>
fn read_line(&mut self, buf: &mut String) -> Result<usize, Error>
Reads all bytes until a newline (the
0xA byte) is reached, and append
them to the provided String buffer. Read moreSource§impl<T: AsRef<[u8]>> Read for ZCursor<T>
impl<T: AsRef<[u8]>> Read for ZCursor<T>
Source§fn read(&mut self, buf: &mut [u8]) -> Result<usize>
fn read(&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
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>
Reads 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>
Reads 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>
Reads 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)Reads 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” adapter for this instance of
Read. Read more1.0.0 · Source§fn chain<R>(self, next: R) -> Chain<Self, R>
fn chain<R>(self, next: R) -> Chain<Self, R>
Creates an adapter which will chain this stream with another. Read more
Source§impl<T: AsRef<[u8]>> Seek for ZCursor<T>
impl<T: AsRef<[u8]>> Seek for ZCursor<T>
Source§fn seek(&mut self, pos: SeekFrom) -> Result<u64>
fn seek(&mut self, pos: SeekFrom) -> Result<u64>
Seek to an offset, in bytes, in a stream. Read more
1.55.0 · Source§fn rewind(&mut self) -> Result<(), Error>
fn rewind(&mut self) -> Result<(), Error>
Rewind to the beginning of a stream. Read more
Source§fn stream_len(&mut self) -> Result<u64, Error>
fn stream_len(&mut self) -> Result<u64, Error>
🔬This is a nightly-only experimental API. (
seek_stream_len)Returns the length of this stream (in bytes). Read more
Auto Trait Implementations§
impl<T> Freeze for ZCursor<T>where
T: Freeze,
impl<T> RefUnwindSafe for ZCursor<T>where
T: RefUnwindSafe,
impl<T> Send for ZCursor<T>where
T: Send,
impl<T> Sync for ZCursor<T>where
T: Sync,
impl<T> Unpin for ZCursor<T>where
T: Unpin,
impl<T> UnsafeUnpin for ZCursor<T>where
T: UnsafeUnpin,
impl<T> UnwindSafe for ZCursor<T>where
T: 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
Source§impl<T> ZByteReaderTrait for T
impl<T> ZByteReaderTrait for T
Source§fn read_byte_no_error(&mut self) -> u8
fn read_byte_no_error(&mut self) -> u8
Read a single byte from the decoder and return
0 if we can’t read the byte, e.g because of EOF Read moreSource§fn read_exact_bytes(&mut self, buf: &mut [u8]) -> Result<(), ZByteIoError>
fn read_exact_bytes(&mut self, buf: &mut [u8]) -> Result<(), ZByteIoError>
Read exact bytes required to fill
buf or return an error if that isn’t possible Read moreSource§fn read_const_bytes<const N: usize>(
&mut self,
buf: &mut [u8; N],
) -> Result<(), ZByteIoError>
fn read_const_bytes<const N: usize>( &mut self, buf: &mut [u8; N], ) -> Result<(), ZByteIoError>
Read exact bytes required to fill
buf or return an error if that isn’t possible Read moreSource§fn read_const_bytes_no_error<const N: usize>(&mut self, buf: &mut [u8; N])
fn read_const_bytes_no_error<const N: usize>(&mut self, buf: &mut [u8; N])
Read exact bytes required to fill
buf or ignore buf entirely if you can’t fill it
due to an error like the inability to fill the buffer completely Read moreSource§fn read_bytes(&mut self, buf: &mut [u8]) -> Result<usize, ZByteIoError>
fn read_bytes(&mut self, buf: &mut [u8]) -> Result<usize, ZByteIoError>
Read bytes into
buf returning how many bytes you have read or an error if one occurred Read moreSource§fn peek_bytes(&mut self, buf: &mut [u8]) -> Result<usize, ZByteIoError>
fn peek_bytes(&mut self, buf: &mut [u8]) -> Result<usize, ZByteIoError>
Reads data into provided buffer but does not advance read position.
fn peek_exact_bytes(&mut self, buf: &mut [u8]) -> Result<(), ZByteIoError>
Source§fn z_seek(&mut self, from: ZSeekFrom) -> Result<u64, ZByteIoError>
fn z_seek(&mut self, from: ZSeekFrom) -> Result<u64, ZByteIoError>
Seek into a new position from the buffer Read more
Source§fn is_eof(&mut self) -> Result<bool, ZByteIoError>
fn is_eof(&mut self) -> Result<bool, ZByteIoError>
Report whether we are at the end of a stream. Read more
Source§fn z_position(&mut self) -> Result<u64, ZByteIoError>
fn z_position(&mut self) -> Result<u64, ZByteIoError>
Return the current position of the inner cursor. Read more
Source§fn read_remaining(&mut self, sink: &mut Vec<u8>) -> Result<usize, ZByteIoError>
fn read_remaining(&mut self, sink: &mut Vec<u8>) -> Result<usize, ZByteIoError>
Read all bytes remaining in this input to
sink until we hit eof Read more