Struct VectoredCursor

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

A cursor that acts as an index over a set of vectored immutable slices and provides operations to sequentially read data from the slices.

When implementing the VectoredRead trait or one of its variants, this cursor provides an interface for reading data from the vectored 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> VectoredCursor<'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 vectored 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 vectored wire if the amount exceeds the number of remaining bytes.

Source

pub fn is_empty(&self) -> bool

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

Source

pub fn get_next(&mut self) -> Result<u8, WireError>

Retrieve a the next available byte from the wire.

Source

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

Deserialize a given type T that implements the VectoredRead trait from the vectored 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>

Deserialize L bytes from the vectored wire into a given type T that implements the VectoredReadPart 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: VectoredReadRef + ?Sized,

Deserialize a given type T that implements the VectoredReadRef trait from the vectored 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: VectoredReadComp<'a> + ?Sized,

Deserialize a given type T that implements the VectoredReadComp 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 remaining(&self) -> usize

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

Source

pub fn try_get(&mut self, amount: usize) -> Option<&'a [u8]>

Attempt to retrieve a contiguous slice of bytes from the wire, returning None if the next amount bytes are not all located on the same slice.

Source

pub fn try_get_array<const L: usize>(&mut self) -> Option<&'a [u8; L]>

Attempt to retrieve a reference to a contiguous array of bytes of size L from the wire, returning None if the next L bytes are not all located on the same slice.

Trait Implementations§

Source§

impl<'a> Clone for VectoredCursor<'a>

Source§

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

Auto Trait Implementations§

§

impl<'a> Freeze for VectoredCursor<'a>

§

impl<'a> RefUnwindSafe for VectoredCursor<'a>

§

impl<'a> Send for VectoredCursor<'a>

§

impl<'a> Sync for VectoredCursor<'a>

§

impl<'a> Unpin for VectoredCursor<'a>

§

impl<'a> UnwindSafe for VectoredCursor<'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.