Skip to main content

StackWriter

Enum StackWriter 

Source
pub enum StackWriter<'a> {
    Stack(SliceWriter<'a>),
    Heap(ByteWriter),
}
Expand description

Stack-first binary writer backed by SliceWriter on the fast path, spilling seamlessly into a heap ByteWriter (Vec<u8>) only when the encoded payload exceeds the stack buffer.

Variants§

§

Stack(SliceWriter<'a>)

§

Heap(ByteWriter)

Implementations§

Source§

impl StackWriter<'static>

Source

pub fn with_capacity(cap: usize) -> Self

Creates a heap-backed writer pre-allocated with cap bytes (reusable across reset() calls).

Source§

impl<'a> StackWriter<'a>

Source

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

Source

pub fn is_spilled(&self) -> bool

Source

pub fn len(&self) -> usize

Source

pub fn is_empty(&self) -> bool

Source

pub fn as_slice(&self) -> &[u8] ⓘ

Source

pub fn reset(&mut self)

Rewinds the writer to length 0, retaining any existing stack slice or spilled heap capacity.

Source

pub fn patch_u32(&mut self, offset: usize, v: u32) -> Result<(), CodecError>

Overwrites an already-written 4-byte little-endian u32 at offset..offset + 4.

Source

pub fn into_vec(self) -> Vec<u8> ⓘ

Source

pub fn write_raw(&mut self, bytes: &[u8]) -> Result<(), CodecError>

Source

pub fn write_zeroes(&mut self, count: usize) -> Result<(), CodecError>

Source

pub fn write_u8(&mut self, v: u8) -> Result<(), CodecError>

Source

pub fn write_i8(&mut self, v: i8) -> Result<(), CodecError>

Source

pub fn write_bool(&mut self, v: bool) -> Result<(), CodecError>

Source

pub fn write_u16(&mut self, v: u16) -> Result<(), CodecError>

Source

pub fn write_i16(&mut self, v: i16) -> Result<(), CodecError>

Source

pub fn write_u32(&mut self, v: u32) -> Result<(), CodecError>

Source

pub fn write_i32(&mut self, v: i32) -> Result<(), CodecError>

Source

pub fn write_u64(&mut self, v: u64) -> Result<(), CodecError>

Source

pub fn write_i64(&mut self, v: i64) -> Result<(), CodecError>

Source

pub fn write_f32(&mut self, v: f32) -> Result<(), CodecError>

Source

pub fn write_f32_raw(&mut self, v: f32) -> Result<(), CodecError>

Source

pub fn write_f64(&mut self, v: f64) -> Result<(), CodecError>

Source

pub fn write_f64_raw(&mut self, v: f64) -> Result<(), CodecError>

Source

pub fn write_len(&mut self, v: usize) -> Result<(), CodecError>

Source

pub fn write_bytes(&mut self, v: &[u8]) -> Result<(), CodecError>

Source

pub fn write_bytes_u16(&mut self, v: &[u8]) -> Result<(), CodecError>

Source

pub fn write_bytes_u8(&mut self, v: &[u8]) -> Result<(), CodecError>

Source

pub fn write_str(&mut self, v: &str) -> Result<(), CodecError>

Source

pub fn write_str_u16(&mut self, v: &str) -> Result<(), CodecError>

Source

pub fn write_str_u8(&mut self, v: &str) -> Result<(), CodecError>

Source

pub fn write_len_max( &mut self, len: usize, max: usize, ) -> Result<(), CodecError>

Source

pub fn write_bytes_max( &mut self, bytes: &[u8], max: usize, ) -> Result<(), CodecError>

Source

pub fn write_str_max(&mut self, s: &str, max: usize) -> Result<(), CodecError>

Source

pub fn write_opt<T>( &mut self, opt: Option<T>, write_some: impl FnOnce(&mut Self, T) -> Result<(), CodecError>, ) -> Result<(), CodecError>

Trait Implementations§

Source§

impl ByteSink for StackWriter<'_>

Source§

fn put_raw(&mut self, bytes: &[u8]) -> Result<(), CodecError>

Source§

fn put_zeroes(&mut self, count: usize) -> Result<(), CodecError>

Source§

fn put_u8(&mut self, v: u8) -> Result<(), CodecError>

Source§

fn put_i8(&mut self, v: i8) -> Result<(), CodecError>

Source§

fn put_bool(&mut self, v: bool) -> Result<(), CodecError>

Source§

fn put_u16(&mut self, v: u16) -> Result<(), CodecError>

Source§

fn put_i16(&mut self, v: i16) -> Result<(), CodecError>

Source§

fn put_u32(&mut self, v: u32) -> Result<(), CodecError>

Source§

fn put_i32(&mut self, v: i32) -> Result<(), CodecError>

Source§

fn put_u64(&mut self, v: u64) -> Result<(), CodecError>

Source§

fn put_i64(&mut self, v: i64) -> Result<(), CodecError>

Source§

fn put_f32(&mut self, v: f32) -> Result<(), CodecError>

Source§

fn put_f32_raw(&mut self, v: f32) -> Result<(), CodecError>

Source§

fn put_f64(&mut self, v: f64) -> Result<(), CodecError>

Source§

fn put_f64_raw(&mut self, v: f64) -> Result<(), CodecError>

Source§

fn put_len(&mut self, len: usize) -> Result<(), CodecError>

Source§

fn put_len_max(&mut self, len: usize, max: usize) -> Result<(), CodecError>

Source§

fn put_bytes(&mut self, bytes: &[u8]) -> Result<(), CodecError>

Source§

fn put_bytes_max(&mut self, bytes: &[u8], max: usize) -> Result<(), CodecError>

Source§

fn put_bytes_u16(&mut self, bytes: &[u8]) -> Result<(), CodecError>

Source§

fn put_bytes_u8(&mut self, bytes: &[u8]) -> Result<(), CodecError>

Source§

fn put_str(&mut self, s: &str) -> Result<(), CodecError>

Source§

fn put_str_max(&mut self, s: &str, max: usize) -> Result<(), CodecError>

Source§

fn put_str_u16(&mut self, s: &str) -> Result<(), CodecError>

Source§

fn put_str_u8(&mut self, s: &str) -> Result<(), CodecError>

Source§

fn put_opt<T>( &mut self, opt: Option<T>, write_some: impl FnOnce(&mut Self, T) -> Result<(), CodecError>, ) -> Result<(), CodecError>
where Self: Sized,

Source§

impl<'a> Debug for StackWriter<'a>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> !UnwindSafe for StackWriter<'a>

§

impl<'a> Forget for StackWriter<'a>

§

impl<'a> Freeze for StackWriter<'a>
where &'a mut [u8]: Freeze, *const u8 is !null: Freeze, PhantomData<u8>: Freeze,

§

impl<'a> Move for StackWriter<'a>

§

impl<'a> RefUnwindSafe for StackWriter<'a>

§

impl<'a> Send for StackWriter<'a>
where RawVecInner: Send,

§

impl<'a> Sync for StackWriter<'a>
where RawVecInner: Sync,

§

impl<'a> Unpin for StackWriter<'a>
where &'a mut [u8]: Unpin, *const u8 is !null: Unpin,

§

impl<'a> UnsafeUnpin for StackWriter<'a>
where &'a mut [u8]: UnsafeUnpin, *const u8 is !null: UnsafeUnpin, PhantomData<u8>: UnsafeUnpin,

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 = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.