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>
impl StackWriter<'static>
Sourcepub fn with_capacity(cap: usize) -> Self
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>
impl<'a> StackWriter<'a>
pub fn new(buf: &'a mut [u8]) -> Self
pub fn is_spilled(&self) -> bool
pub fn len(&self) -> usize
pub fn is_empty(&self) -> bool
pub fn as_slice(&self) -> &[u8] ⓘ
Sourcepub fn reset(&mut self)
pub fn reset(&mut self)
Rewinds the writer to length 0, retaining any existing stack slice or spilled heap capacity.
Sourcepub fn patch_u32(&mut self, offset: usize, v: u32) -> Result<(), CodecError>
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.
pub fn into_vec(self) -> Vec<u8> ⓘ
pub fn write_raw(&mut self, bytes: &[u8]) -> Result<(), CodecError>
pub fn write_zeroes(&mut self, count: usize) -> Result<(), CodecError>
pub fn write_u8(&mut self, v: u8) -> Result<(), CodecError>
pub fn write_i8(&mut self, v: i8) -> Result<(), CodecError>
pub fn write_bool(&mut self, v: bool) -> Result<(), CodecError>
pub fn write_u16(&mut self, v: u16) -> Result<(), CodecError>
pub fn write_i16(&mut self, v: i16) -> Result<(), CodecError>
pub fn write_u32(&mut self, v: u32) -> Result<(), CodecError>
pub fn write_i32(&mut self, v: i32) -> Result<(), CodecError>
pub fn write_u64(&mut self, v: u64) -> Result<(), CodecError>
pub fn write_i64(&mut self, v: i64) -> Result<(), CodecError>
pub fn write_f32(&mut self, v: f32) -> Result<(), CodecError>
pub fn write_f32_raw(&mut self, v: f32) -> Result<(), CodecError>
pub fn write_f64(&mut self, v: f64) -> Result<(), CodecError>
pub fn write_f64_raw(&mut self, v: f64) -> Result<(), CodecError>
pub fn write_len(&mut self, v: usize) -> Result<(), CodecError>
pub fn write_bytes(&mut self, v: &[u8]) -> Result<(), CodecError>
pub fn write_bytes_u16(&mut self, v: &[u8]) -> Result<(), CodecError>
pub fn write_bytes_u8(&mut self, v: &[u8]) -> Result<(), CodecError>
pub fn write_str(&mut self, v: &str) -> Result<(), CodecError>
pub fn write_str_u16(&mut self, v: &str) -> Result<(), CodecError>
pub fn write_str_u8(&mut self, v: &str) -> Result<(), CodecError>
pub fn write_len_max( &mut self, len: usize, max: usize, ) -> Result<(), CodecError>
pub fn write_bytes_max( &mut self, bytes: &[u8], max: usize, ) -> Result<(), CodecError>
pub fn write_str_max(&mut self, s: &str, max: usize) -> Result<(), CodecError>
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<'_>
impl ByteSink for StackWriter<'_>
fn put_raw(&mut self, bytes: &[u8]) -> Result<(), CodecError>
fn put_zeroes(&mut self, count: usize) -> Result<(), CodecError>
fn put_u8(&mut self, v: u8) -> Result<(), CodecError>
fn put_i8(&mut self, v: i8) -> Result<(), CodecError>
fn put_bool(&mut self, v: bool) -> Result<(), CodecError>
fn put_u16(&mut self, v: u16) -> Result<(), CodecError>
fn put_i16(&mut self, v: i16) -> Result<(), CodecError>
fn put_u32(&mut self, v: u32) -> Result<(), CodecError>
fn put_i32(&mut self, v: i32) -> Result<(), CodecError>
fn put_u64(&mut self, v: u64) -> Result<(), CodecError>
fn put_i64(&mut self, v: i64) -> Result<(), CodecError>
fn put_f32(&mut self, v: f32) -> Result<(), CodecError>
fn put_f32_raw(&mut self, v: f32) -> Result<(), CodecError>
fn put_f64(&mut self, v: f64) -> Result<(), CodecError>
fn put_f64_raw(&mut self, v: f64) -> Result<(), CodecError>
fn put_len(&mut self, len: usize) -> Result<(), CodecError>
fn put_len_max(&mut self, len: usize, max: usize) -> Result<(), CodecError>
fn put_bytes(&mut self, bytes: &[u8]) -> Result<(), CodecError>
fn put_bytes_max(&mut self, bytes: &[u8], max: usize) -> Result<(), CodecError>
fn put_bytes_u16(&mut self, bytes: &[u8]) -> Result<(), CodecError>
fn put_bytes_u8(&mut self, bytes: &[u8]) -> Result<(), CodecError>
fn put_str(&mut self, s: &str) -> Result<(), CodecError>
fn put_str_max(&mut self, s: &str, max: usize) -> Result<(), CodecError>
fn put_str_u16(&mut self, s: &str) -> Result<(), CodecError>
fn put_str_u8(&mut self, s: &str) -> Result<(), CodecError>
fn put_opt<T>(
&mut self,
opt: Option<T>,
write_some: impl FnOnce(&mut Self, T) -> Result<(), CodecError>,
) -> Result<(), CodecError>where
Self: Sized,
Auto Trait Implementations§
impl<'a> !UnwindSafe for StackWriter<'a>
impl<'a> Forget for StackWriter<'a>
impl<'a> Freeze for StackWriter<'a>
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>
impl<'a> UnsafeUnpin for StackWriter<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more