Skip to main content

ZCursor

Struct ZCursor 

Source
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: usize

Implementations§

Source§

impl<T: AsRef<[u8]>> ZCursor<T>

Source

pub fn new(buffer: T) -> ZCursor<T>

Source§

impl<T: AsRef<[u8]>> ZCursor<T>

Source

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

Source

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

Source

pub fn split(&self) -> (&[u8], &[u8])

Source§

impl<T: AsRef<[u8]>> ZCursor<T>

Source

pub(crate) fn read_byte_no_error_impl(&mut self) -> u8

Source

pub(crate) fn read_exact_bytes_impl( &mut self, buf: &mut [u8], ) -> Result<(), ZByteIoError>

Source

pub(crate) fn read_const_bytes_impl<const N: usize>( &mut self, buf: &mut [u8; N], ) -> Result<(), ZByteIoError>

Source

pub(crate) fn read_const_bytes_no_error_impl<const N: usize>( &mut self, buf: &mut [u8; N], )

Source

pub(crate) fn read_bytes_impl( &mut self, buf: &mut [u8], ) -> Result<usize, ZByteIoError>

Source

pub(crate) fn peek_bytes_impl( &mut self, buf: &mut [u8], ) -> Result<usize, ZByteIoError>

Source

pub(crate) fn peek_exact_bytes_impl( &mut self, buf: &mut [u8], ) -> Result<(), ZByteIoError>

Source

pub(crate) fn z_seek_impl( &mut self, from: ZSeekFrom, ) -> Result<u64, ZByteIoError>

Source

pub(crate) fn is_eof_impl(&mut self) -> Result<bool, ZByteIoError>

Source

pub(crate) fn z_position_impl(&mut self) -> Result<u64, ZByteIoError>

Source

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>

Source§

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 more
Source§

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 more
Source§

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 more
1.0.0 · Source§

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

Reads all bytes into buf until the delimiter byte or EOF is reached. Read more
1.83.0 · Source§

fn skip_until(&mut self, byte: u8) -> Result<usize, Error>

Skips all bytes until the delimiter byte or EOF is reached. Read more
1.0.0 · Source§

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 more
1.0.0 · Source§

fn split(self, byte: u8) -> Split<Self>
where Self: Sized,

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

fn lines(self) -> Lines<Self>
where Self: Sized,

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

impl<T: AsRef<[u8]>> From<T> for ZCursor<T>

Source§

fn from(value: T) -> Self

Converts to this type from the input type.
Source§

impl<T: AsRef<[u8]>> Read for ZCursor<T>

Source§

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>

Like read, except that it reads into a slice of buffers. Read more
Source§

fn is_read_vectored(&self) -> bool

🔬This is a nightly-only experimental API. (can_vector)
Determines if this Reader has an efficient read_vectored implementation. Read more
1.0.0 · Source§

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 more
1.0.0 · Source§

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 more
1.6.0 · Source§

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

Reads the exact number of bytes required to fill buf. Read more
Source§

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>

🔬This is a nightly-only experimental API. (read_buf)
Reads the exact number of bytes required to fill cursor. Read more
1.0.0 · Source§

fn by_ref(&mut self) -> &mut Self
where Self: Sized,

Creates a “by reference” adapter for this instance of Read. Read more
1.0.0 · Source§

fn bytes(self) -> Bytes<Self>
where Self: Sized,

Transforms this Read instance to an Iterator over its bytes. Read more
1.0.0 · Source§

fn chain<R>(self, next: R) -> Chain<Self, R>
where R: Read, Self: Sized,

Creates an adapter which will chain this stream with another. Read more
1.0.0 · Source§

fn take(self, limit: u64) -> Take<Self>
where Self: Sized,

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

fn read_array<const N: usize>(&mut self) -> Result<[u8; N], Error>
where Self: Sized,

🔬This is a nightly-only experimental API. (read_array)
Read and return a fixed array of bytes from this source. Read more
Source§

impl<T: AsRef<[u8]>> Seek for ZCursor<T>

Source§

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>

Rewind to the beginning of a stream. Read more
Source§

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
1.51.0 · Source§

fn stream_position(&mut self) -> Result<u64, Error>

Returns the current seek position from the start of the stream. Read more
1.80.0 · Source§

fn seek_relative(&mut self, offset: i64) -> Result<(), Error>

Seeks relative to the current position. 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> 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>,

Source§

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

Source§

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.
Source§

impl<T> ZByteReaderTrait for T
where T: BufRead + Seek,

Source§

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 more
Source§

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 more
Source§

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 more
Source§

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 more
Source§

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 more
Source§

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

Reads data into provided buffer but does not advance read position.
Source§

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

Source§

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>

Report whether we are at the end of a stream. Read more
Source§

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>

Read all bytes remaining in this input to sink until we hit eof Read more