Struct WireCursorMut

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

A cursor that acts as an index over a mutable slice and provides operations to sequentially write data to it.

When implementing the WireWrite trait or one of its variants, this cursor provides an interface for writing data to 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 write data from a wire in the same manner as a WireWriter. A WireWriter is guaranteed to maintain the index of its last succesful write 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> WireCursorMut<'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 is_empty(&self) -> bool

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

Source

pub fn put_slice(&mut self, slice: &[u8]) -> Result<(), WireError>

Write a slice of bytes to the wire.

Source

pub fn put_writable<T, const E: bool>( &mut self, writable: &T, ) -> Result<(), WireError>
where T: WireWrite + ?Sized,

Serialize a given type T that implements the WireWrite trait to the wire.

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

Source

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

Serialize L bytes to the wire from a given type T that implements the WireWritePart trait.

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

Source

pub fn remaining(&self) -> usize

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

Auto Trait Implementations§

§

impl<'a> Freeze for WireCursorMut<'a>

§

impl<'a> RefUnwindSafe for WireCursorMut<'a>

§

impl<'a> Send for WireCursorMut<'a>

§

impl<'a> Sync for WireCursorMut<'a>

§

impl<'a> Unpin for WireCursorMut<'a>

§

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