Packer

Struct Packer 

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

Packer of POD values into a StructBuf.

The packer maintains an index (0 <= i <= lim()) where new values are written, which is incremented after each write. Write operations panic if the buffer capacity limit is exceeded.

The packer intentionally does not expose the underlying StructBuf to guarantee append-only operation.

Little-endian encoding is assumed.

Implementations§

Source§

impl Packer<'_>

Source

pub const fn position(&self) -> usize

Returns the current index.

Source

pub fn remaining(&self) -> usize

Returns the number of additional bytes that can be written.

Source

pub fn skip(&mut self, n: usize) -> &mut Self

Advances the current index by n bytes.

Source

pub fn bool<T: Into<bool>>(&mut self, v: T) -> &mut Self

Writes a bool as a u8 at the current index.

Source

pub fn u8<T: Into<u8>>(&mut self, v: T) -> &mut Self

Writes a u8 at the current index.

Source

pub fn u16<T: Into<u16>>(&mut self, v: T) -> &mut Self

Writes a u16 at the current index.

Source

pub fn u24<T: Into<u32>>(&mut self, v: T) -> &mut Self

Writes a u32 as a u24 at the current index.

§Panics

Panics if v cannot be represented in 24 bits.

Source

pub fn u32<T: Into<u32>>(&mut self, v: T) -> &mut Self

Writes a u32 at the current index.

Source

pub fn u64<T: Into<u64>>(&mut self, v: T) -> &mut Self

Writes a u64 at the current index.

Source

pub fn u128<T: Into<u128>>(&mut self, v: T) -> &mut Self

Writes a u128 at the current index.

Source

pub fn i8<T: Into<i8>>(&mut self, v: T) -> &mut Self

Writes an i8 at the current index.

Source

pub fn i16<T: Into<i16>>(&mut self, v: T) -> &mut Self

Writes an i16 at the current index.

Source

pub fn i32<T: Into<i32>>(&mut self, v: T) -> &mut Self

Writes an i32 at the current index.

Source

pub fn i64<T: Into<i64>>(&mut self, v: T) -> &mut Self

Writes an i64 at the current index.

Source

pub fn i128<T: Into<i128>>(&mut self, v: T) -> &mut Self

Writes an i128 at the current index.

Source

pub const fn can_put(&self, n: usize) -> bool

Returns whether n bytes can be written at the current index.

Source

pub fn put<T: AsRef<[u8]>>(&mut self, v: T) -> &mut Self

Writes v at the current index.

Trait Implementations§

Source§

impl AsMut<[u8]> for Packer<'_>

Source§

fn as_mut(&mut self) -> &mut [u8]

Converts this type into a mutable reference of the (usually inferred) input type.
Source§

impl AsRef<[u8]> for Packer<'_>

Source§

fn as_ref(&self) -> &[u8]

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<'a> Debug for Packer<'a>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl From<&mut Packer<'_>> for ()

Allows terminating packer method calls with .into().

Source§

fn from(_: &mut Packer<'_>) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl<'a> Freeze for Packer<'a>

§

impl<'a> RefUnwindSafe for Packer<'a>

§

impl<'a> Send for Packer<'a>

§

impl<'a> Sync for Packer<'a>

§

impl<'a> Unpin for Packer<'a>

§

impl<'a> !UnwindSafe for Packer<'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.
Source§

impl<T> Unpack for T
where T: AsRef<[u8]>,

Source§

fn unpack(&self) -> Unpacker<'_>

Returns an unpacker for reading values from the start of the buffer.