Skip to main content

ZeroBuilder

Struct ZeroBuilder 

Source
pub struct ZeroBuilder { /* private fields */ }
Available on crate features alloc and zero-copy only.
Expand description

A builder for zero-copy structures.

Implementations§

Source§

impl ZeroBuilder

Source

pub const fn new() -> Self

Creates a new instance.

Source

pub fn align(&mut self, align: usize) -> usize

Aligns the builder to the specified boundary.

Source

pub fn reserve<T: ZeroCopy>(&mut self) -> usize

Reserves space for a value of type T.

Source

pub fn reserve_bytes(&mut self, size: usize, align: usize) -> usize

Reserves a specific number of bytes with alignment.

Source

pub fn write<T: ZeroCopy>(&mut self, offset: usize, val: &T)

Writes a value to the specified offset.

Source

pub fn push<T: ZeroCopy>(&mut self, val: &T) -> usize

Pushes a value onto the builder and returns its offset.

Source

pub fn push_bytes(&mut self, bytes: &[u8], align: usize) -> usize

Pushes raw bytes onto the builder.

Source

pub fn finish(self) -> AlignedBuffer

Finalizes the builder and returns the AlignedBuffer.

Source

pub const fn len(&self) -> usize

Returns the current length of the buffer.

Source

pub const fn is_empty(&self) -> bool

Returns true if the buffer is empty.

Trait Implementations§

Source§

impl Default for ZeroBuilder

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

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.