Skip to main content

SliceWriter

Struct SliceWriter 

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

Zero-allocation little-endian binary writer over a caller-owned &mut [u8] slice.

Implementations§

Source§

impl<'a> SliceWriter<'a>

Source

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

Source

pub const fn pos(&self) -> usize

Source

pub const fn remaining(&self) -> usize

Source

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

Source

pub fn reset(&mut self)

Rewinds the write cursor back to offset 0 without reallocating or touching the backing slice.

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

Source

pub fn finish(self) -> Result<(), CodecError>

Verifies that the destination slice was filled completely with zero unused trailing bytes.

Trait Implementations§

Source§

impl ByteSink for SliceWriter<'_>

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 SliceWriter<'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 SliceWriter<'a>

§

impl<'a> Forget for SliceWriter<'a>

§

impl<'a> Freeze for SliceWriter<'a>
where &'a mut [u8]: Freeze,

§

impl<'a> Move for SliceWriter<'a>

§

impl<'a> RefUnwindSafe for SliceWriter<'a>

§

impl<'a> Send for SliceWriter<'a>

§

impl<'a> Sync for SliceWriter<'a>

§

impl<'a> Unpin for SliceWriter<'a>
where &'a mut [u8]: Unpin,

§

impl<'a> UnsafeUnpin for SliceWriter<'a>
where &'a mut [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.