Struct canadensis_encoding::WriteCursor
source · [−]pub struct WriteCursor<'b> { /* private fields */ }
Expand description
A cursor over a byte slice for easy serializing of UAVCAN data types
Functions that write values will panic if no space is available in the slice.
Implementations
sourceimpl<'b> WriteCursor<'b>
impl<'b> WriteCursor<'b>
sourcepub fn new(bytes: &'b mut [u8]) -> Self
pub fn new(bytes: &'b mut [u8]) -> Self
Creates a cursor that will write starting at the beginning of the provided slice
sourcepub fn is_aligned_to_8_bits(&self) -> bool
pub fn is_aligned_to_8_bits(&self) -> bool
Returns true if this cursor is aligned to a multiple of 8 bits
sourcepub fn write_aligned_u8(&mut self, value: u8)
pub fn write_aligned_u8(&mut self, value: u8)
Writes an 8-bit integer
Panics
This function panics if the cursor is not aligned to a multiple of 8 bits.
sourcepub fn write_aligned_u16(&mut self, value: u16)
pub fn write_aligned_u16(&mut self, value: u16)
Writes a 16-bit integer
Panics
This function panics if the cursor is not aligned to a multiple of 8 bits.
sourcepub fn write_aligned_u32(&mut self, value: u32)
pub fn write_aligned_u32(&mut self, value: u32)
Writes a 32-bit integer
Panics
This function panics if the cursor is not aligned to a multiple of 8 bits.
sourcepub fn write_aligned_u64(&mut self, value: u64)
pub fn write_aligned_u64(&mut self, value: u64)
Writes a 64-bit integer
Panics
This function panics if the cursor is not aligned to a multiple of 8 bits.
sourcepub fn align_to_8_bits(&mut self)
pub fn align_to_8_bits(&mut self)
Advances the cursor to a byte boundary (a multiple of 8 bits)
sourcepub fn write_bytes(&mut self, bytes: &[u8])
pub fn write_bytes(&mut self, bytes: &[u8])
Writes a byte array
sourcepub fn write_aligned_bytes(&mut self, bytes: &[u8])
pub fn write_aligned_bytes(&mut self, bytes: &[u8])
Writes a sequence of bytes
Panics
This function panics if the cursor is not aligned to a multiple of 8 bits.
sourcepub fn write_composite<T>(&mut self, value: &T) where
T: Serialize,
pub fn write_composite<T>(&mut self, value: &T) where
T: Serialize,
Writes a composite value, aligned to 8 bits
sourcepub fn write_bool(&mut self, value: bool)
pub fn write_bool(&mut self, value: bool)
Writes a boolean value (1 bit)
sourcepub fn bits_written(&self) -> usize
pub fn bits_written(&self) -> usize
Returns the number of bits that have been written to this cursor
sourceimpl WriteCursor<'_>
impl WriteCursor<'_>
sourceimpl WriteCursor<'_>
impl WriteCursor<'_>
Auto Trait Implementations
impl<'b> RefUnwindSafe for WriteCursor<'b>
impl<'b> Send for WriteCursor<'b>
impl<'b> Sync for WriteCursor<'b>
impl<'b> Unpin for WriteCursor<'b>
impl<'b> !UnwindSafe for WriteCursor<'b>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more