Struct WireCursor

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

A cursor that acts as an index over a contiguous immutable slice and provides operations to sequentially read data from it.

When implementing the WireRead trait or one of its variants, this cursor provides an interface for reading data from the wire. When an error is returned by the cursor, it should be returned by the trait method being implemented. This can be easily accomplished using the ? operator.

NOTE: this is an internal structure, and is NOT meant to be used to read data from a wire in the same manner as a WireReader. A WireReader is guaranteed to maintain the index of its last succesful read if any of its methods return an error, while this cursor may move its internal index forward by some unspecified amount when an error is encountered.

Implementations§

Source§

impl<'a> WireCursor<'a>

Source

pub fn advance(&mut self, amount: usize) -> Result<(), WireError>

Advance the cursor’s index by the given amount, returning an error if there are insufficient bytes on the wire.

Source

pub fn advance_up_to(&mut self, amount: usize)

Advance the cursor’s index by the given amount, or to the end of the wire if the amount exceeds the number of remaining bytes.

Source

pub fn get_array<const L: usize>(&mut self) -> Result<&'a [u8; L], WireError>

Retrieve a reference to an array of bytes of size L from the wire.

Source

pub fn get_readable<T, const E: bool>(&mut self) -> Result<T, WireError>
where T: WireRead,

Deserialize a given type T that implements the WireRead trait from the wire, and return an owned instance of it.

The generic boolean E designates the intended endianness of the data being read. If E is set to true, then the data will be deserialized in big endian format; if false, it will be deserialized in little endian.

Source

pub fn get_readable_part<T, const L: usize, const E: bool>( &mut self, ) -> Result<T, WireError>
where T: WireReadPart,

Deserialize L bytes from the wire into a given type T that implements the WireReadPart trait, and return an owned instance of it.

The generic boolean E designates the intended endianness of the data being read. If E is set to true, then the data will be deserialized in big endian format; if false, it will be deserialized in little endian.

Source

pub fn get_readable_ref<T, const E: bool>( &mut self, length: usize, ) -> Result<&'a T, WireError>
where T: WireReadRef + ?Sized,

Deserialize a given type T that implements the WireReadRef trait from the wire, and return a reference to it.

The generic boolean E designates the intended endianness of the data being read. If E is set to true, then the data will be deserialized in big endian format; if false, it will be deserialized in little endian.

Source

pub fn get_readable_comp<T, const E: bool>(&mut self) -> Result<T, WireError>
where T: WireReadComp<'a> + ?Sized,

Deserialize a given type T that implements the WireReadComp trait from the wire, and return an owned instance of it.

The generic boolean E designates the intended endianness of the data being read. If E is set to true, then the data will be deserialized in big endian format; if false, it will be deserialized in little endian.

Source

pub fn get_slice(&mut self, amount: usize) -> Result<&'a [u8], WireError>

Retrieve a slice of bytes from the wire.

Source

pub fn is_empty(&self) -> bool

Check whether the wire has any remaining bytes that can be read by the cursor.

Source

pub fn remaining(&self) -> usize

Get the number of bytes remaining on the wire for the given cursor.

Trait Implementations§

Source§

impl<'a> Clone for WireCursor<'a>

Source§

fn clone(&self) -> WireCursor<'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> Copy for WireCursor<'a>

Auto Trait Implementations§

§

impl<'a> Freeze for WireCursor<'a>

§

impl<'a> RefUnwindSafe for WireCursor<'a>

§

impl<'a> Send for WireCursor<'a>

§

impl<'a> Sync for WireCursor<'a>

§

impl<'a> Unpin for WireCursor<'a>

§

impl<'a> UnwindSafe for WireCursor<'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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.