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>
impl<'a> WireCursorMut<'a>
Sourcepub fn advance(&mut self, amount: usize) -> Result<(), WireError>
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.
Sourcepub fn advance_up_to(&mut self, amount: usize)
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.
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Check whether the vectored wire has any remaining bytes that can be written to by the cursor.
Sourcepub fn put_slice(&mut self, slice: &[u8]) -> Result<(), WireError>
pub fn put_slice(&mut self, slice: &[u8]) -> Result<(), WireError>
Write a slice of bytes to the wire.
Sourcepub fn put_writable<T, const E: bool>(
&mut self,
writable: &T,
) -> Result<(), WireError>
pub fn put_writable<T, const E: bool>( &mut self, writable: &T, ) -> Result<(), WireError>
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.
Sourcepub fn put_writable_part<T, const L: usize, const E: bool>(
&mut self,
writable: &T,
) -> Result<(), WireError>where
T: WireWritePart,
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.