Struct ReadCursor

Source
pub struct ReadCursor<'a> { /* private fields */ }
Expand description

A cursor for reading bytes from a buffer.

Implementations§

Source§

impl<'a> ReadCursor<'a>

Source

pub const fn new(bytes: &'a [u8]) -> Self

Create a new ReadCursor from a byte slice.

Source

pub const fn len(&self) -> usize

Returns the number of bytes remaining.

Source

pub const fn is_empty(&self) -> bool

Returns true if there are no bytes remaining.

Source

pub const fn eof(&self) -> bool

Returns true if there are no bytes remaining.

Source

pub fn remaining(&self) -> &'a [u8]

Returns a slice of the remaining bytes.

Source

pub const fn split_at_peek( &self, mid: usize, ) -> (ReadCursor<'a>, ReadCursor<'a>)

Returns two cursors, one with the first mid bytes and the other with the remaining bytes.

Source

pub fn split_at(&mut self, mid: usize) -> (ReadCursor<'a>, ReadCursor<'a>)

Returns two cursors, one with the first mid bytes and the other with the remaining bytes.

The current cursor will be moved to the end.

Source

pub const fn inner(&self) -> &[u8]

Return the inner byte slice.

Source

pub const fn pos(&self) -> usize

Returns the current position.

Source

pub fn read_array<const N: usize>(&mut self) -> [u8; N]

Read an array of N bytes.

Source

pub fn read_slice(&mut self, n: usize) -> &'a [u8]

Read a slice of n bytes.

Source

pub fn read_remaining(&mut self) -> &[u8]

Read the remaining bytes.

Source

pub fn read_u8(&mut self) -> u8

Read a u8.

Source

pub fn try_read_u8(&mut self) -> Result<u8, NotEnoughBytesError>

Try to read a u8.

Source

pub fn read_i16(&mut self) -> i16

Read a i16.

Source

pub fn read_i16_be(&mut self) -> i16

Read a i16 in big-endian.

Source

pub fn try_read_i16(&mut self) -> Result<i16, NotEnoughBytesError>

Try to read a i16.

Source

pub fn try_read_i16_be(&mut self) -> Result<i16, NotEnoughBytesError>

Try to read a i16 in big-endian.

Source

pub fn read_u16(&mut self) -> u16

Read a u16.

Source

pub fn read_u16_be(&mut self) -> u16

Read a u16 in big-endian.

Source

pub fn try_read_u16(&mut self) -> Result<u16, NotEnoughBytesError>

Try to read a u16.

Source

pub fn try_read_u16_be(&mut self) -> Result<u16, NotEnoughBytesError>

Try to read a u16 in big-endian.

Source

pub fn read_u32(&mut self) -> u32

Read a u32.

Source

pub fn read_u32_be(&mut self) -> u32

Read a u32 in big-endian.

Source

pub fn try_read_u32(&mut self) -> Result<u32, NotEnoughBytesError>

Try to read a u32.

Source

pub fn try_read_u32_be(&mut self) -> Result<u32, NotEnoughBytesError>

Try to read a u32 in big-endian.

Source

pub fn read_u64(&mut self) -> u64

Read a u64.

Source

pub fn read_u64_be(&mut self) -> u64

Read a u64 in big-endian.

Source

pub fn try_read_u64(&mut self) -> Result<u64, NotEnoughBytesError>

Try to read a u64.

Source

pub fn try_read_u64_be(&mut self) -> Result<u64, NotEnoughBytesError>

Try to read a u64 in big-endian.

Source

pub fn read_i32(&mut self) -> i32

Read a i32.

Source

pub fn read_i32_be(&mut self) -> i32

Read a i32 in big-endian.

Source

pub fn try_read_i32(&mut self) -> Result<i32, NotEnoughBytesError>

Try to read a i32.

Source

pub fn try_read_i32_be(&mut self) -> Result<i32, NotEnoughBytesError>

Try to read a i32 in big-endian.

Source

pub fn read_i64(&mut self) -> i64

Read a i64.

Source

pub fn read_i64_be(&mut self) -> i64

Read a i64 in big-endian.

Source

pub fn try_read_i64(&mut self) -> Result<i64, NotEnoughBytesError>

Try to read a i64.

Source

pub fn try_read_i64_be(&mut self) -> Result<i64, NotEnoughBytesError>

Try to read a i64 in big-endian.

Source

pub fn read_u128(&mut self) -> u128

Read a u128.

Source

pub fn read_u128_be(&mut self) -> u128

Read a u128 in big-endian.

Source

pub fn try_read_u128(&mut self) -> Result<u128, NotEnoughBytesError>

Try to read a u128.

Source

pub fn try_read_u128_be(&mut self) -> Result<u128, NotEnoughBytesError>

Try to read a u128 in big-endian.

Source

pub fn peek<const N: usize>(&mut self) -> [u8; N]

Peek at the next N bytes without consuming them.

Source

pub fn peek_slice(&mut self, n: usize) -> &'a [u8]

Peek at the next N bytes without consuming them.

Source

pub fn peek_u8(&mut self) -> u8

Peek a u8 without consuming it.

Source

pub fn try_peek_u8(&mut self) -> Result<u8, NotEnoughBytesError>

Try to peek a u8 without consuming it.

Source

pub fn peek_u16(&mut self) -> u16

Peek a u16 without consuming it.

Source

pub fn peek_u16_be(&mut self) -> u16

Peek a big-endian u16 without consuming it.

Source

pub fn try_peek_u16(&mut self) -> Result<u16, NotEnoughBytesError>

Try to peek a u16 without consuming it.

Source

pub fn try_peek_u16_be(&mut self) -> Result<u16, NotEnoughBytesError>

Try to peek a big-endian u16 without consuming it.

Source

pub fn peek_u32(&mut self) -> u32

Peek a u32 without consuming it.

Source

pub fn peek_u32_be(&mut self) -> u32

Peek a big-endian u32 without consuming it.

Source

pub fn try_peek_u32(&mut self) -> Result<u32, NotEnoughBytesError>

Try to peek a u32 without consuming it.

Source

pub fn try_peek_u32_be(&mut self) -> Result<u32, NotEnoughBytesError>

Try to peek a big-endian u32 without consuming it.

Source

pub fn peek_u64(&mut self) -> u64

Peek a u64 without consuming it.

Source

pub fn peek_u64_be(&mut self) -> u64

Peek a big-endian u64 without consuming it.

Source

pub fn try_peek_u64(&mut self) -> Result<u64, NotEnoughBytesError>

Try to peek a u64 without consuming it.

Source

pub fn try_peek_u64_be(&mut self) -> Result<u64, NotEnoughBytesError>

Try to peek a big-endian u64 without consuming it.

Source

pub fn advance(&mut self, len: usize)

Advance the cursor by len bytes.

Source

pub const fn advanced(&'a self, len: usize) -> ReadCursor<'a>

Return a new cursor advanced by len bytes.

Source

pub fn rewind(&mut self, len: usize)

Rewind the cursor by len bytes.

Source

pub const fn rewinded(&'a self, len: usize) -> ReadCursor<'a>

Return a new cursor rewinded by len bytes.

Trait Implementations§

Source§

impl<'a> Clone for ReadCursor<'a>

Source§

fn clone(&self) -> ReadCursor<'a>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Debug for ReadCursor<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for ReadCursor<'a>

§

impl<'a> RefUnwindSafe for ReadCursor<'a>

§

impl<'a> Send for ReadCursor<'a>

§

impl<'a> Sync for ReadCursor<'a>

§

impl<'a> Unpin for ReadCursor<'a>

§

impl<'a> UnwindSafe for ReadCursor<'a>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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.