Struct WriteCursor

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

A cursor for writing bytes to a buffer.

Implementations§

Source§

impl<'a> WriteCursor<'a>

Source

pub fn new(bytes: &'a mut [u8]) -> Self

Create a new WriteCursor from a mutable slice of bytes.

Source

pub const fn len(&self) -> usize

Returns the number of bytes remaining.

Source

pub const fn is_empty(&self) -> bool

Returns true if there are no bytes remaining.

Source

pub const fn eof(&self) -> bool

Returns true if there are no bytes remaining.

Source

pub fn remaining(&self) -> &[u8]

Returns a slice of the remaining bytes.

Source

pub fn remaining_mut(&mut self) -> &mut [u8]

Returns a mutable slice of the remaining bytes.

Source

pub const fn inner(&self) -> &[u8]

Returns the inner byte slice.

Source

pub fn inner_mut(&mut self) -> &mut [u8]

Returns the inner mutable byte slice.

Source

pub const fn pos(&self) -> usize

Returns the current position of the cursor.

Source

pub fn write_array<const N: usize>(&mut self, array: [u8; N])

Write an array of bytes to the buffer.

Source

pub fn write_slice(&mut self, slice: &[u8])

Write a slice of bytes to the buffer.

Source

pub fn write_u8(&mut self, value: u8)

Write a byte to the buffer.

Source

pub fn write_i8(&mut self, value: i8)

Write a signed byte to the buffer.

Source

pub fn write_u16(&mut self, value: u16)

Write a little-endian u16 to the buffer.

Source

pub fn write_u16_be(&mut self, value: u16)

Write a big-endian u16 to the buffer.

Source

pub fn write_i16(&mut self, value: i16)

Write a signed little-endian i16 to the buffer.

Source

pub fn write_i16_be(&mut self, value: i16)

Write a signed big-endian i16 to the buffer.

Source

pub fn write_u32(&mut self, value: u32)

Write a little-endian u32 to the buffer.

Source

pub fn write_u32_be(&mut self, value: u32)

Write a big-endian u32 to the buffer.

Source

pub fn write_i32(&mut self, value: i32)

Write a signed little-endian i32 to the buffer.

Source

pub fn write_u64(&mut self, value: u64)

Write a little-endian u64 to the buffer.

Source

pub fn write_u64_be(&mut self, value: u64)

Write a big-endian u64 to the buffer.

Source

pub fn write_i64(&mut self, value: i64)

Write a signed little-endian i64 to the buffer.

Source

pub fn write_i64_be(&mut self, value: i64)

Write a signed big-endian i64 to the buffer.

Source

pub fn write_u128(&mut self, value: u128)

Write a little-endian u128 to the buffer.

Source

pub fn write_u128_be(&mut self, value: u128)

Write a big-endian u128 to the buffer.

Source

pub fn advance(&mut self, len: usize)

Advance the cursor by len bytes.

Source

pub fn advanced(&'a mut self, len: usize) -> WriteCursor<'a>

Returns a new cursor advanced by len bytes.

Source

pub fn rewind(&mut self, len: usize)

Rewind the cursor by len bytes.

Source

pub fn rewinded(&'a mut self, len: usize) -> WriteCursor<'a>

Returns a new cursor rewinded by len bytes.

Trait Implementations§

Source§

impl<'a> Debug for WriteCursor<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for WriteCursor<'a>

§

impl<'a> RefUnwindSafe for WriteCursor<'a>

§

impl<'a> Send for WriteCursor<'a>

§

impl<'a> Sync for WriteCursor<'a>

§

impl<'a> Unpin for WriteCursor<'a>

§

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