Writer

Struct Writer 

Source
pub struct Writer<W: Write> { /* private fields */ }
Expand description

The writer type used in [storekey::Encode].

Handles writing into the encoding buffer and escaping bytes if needed.

Will only escape bytes where they might conflict with a terminal zero byte. To do have this function correctly you need to call Writer::mark_terminator function where appropriate.

Implementations§

Source§

impl<W: Write> Writer<W>

Source

pub const fn new(w: W) -> Self

Source

pub fn mark_terminator(&mut self)

Marks a position where a null byte is used as a terminator.

Should be called if when decoding a zero byte as the next character would result in the serialize ending prematurely.

Source

pub fn write_escaped_slice( &mut self, slice: &EscapedSlice, ) -> Result<(), EncodeError>

Write an already escaped slice.

Source

pub fn write_slice(&mut self, slice: &[u8]) -> Result<(), EncodeError>

Writes an runtime sized slice, escaping null bytes and ending the slice with a terminal zero byte.

Source

pub fn write_array<const LEN: usize>( &mut self, array: [u8; LEN], ) -> Result<(), EncodeError>

Write a fixed size array into the buffer.

As it is fixed size it will not write a terminal zero byte after the end.

This function will escape the first byte of the array if needed. All other write_* functions which write fixed sized types call this function.

Source

pub fn write_terminator(&mut self) -> Result<(), EncodeError>

Source

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

Source

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

Source

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

Source

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

Source

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

Source

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

Source

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

Source

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

Source

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

Source

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

Source

pub fn write_i128(&mut self, v: i128) -> Result<(), EncodeError>

Source

pub fn write_u128(&mut self, v: u128) -> Result<(), EncodeError>

Trait Implementations§

Source§

impl<W: Debug + Write> Debug for Writer<W>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<W> Freeze for Writer<W>
where W: Freeze,

§

impl<W> RefUnwindSafe for Writer<W>
where W: RefUnwindSafe,

§

impl<W> Send for Writer<W>
where W: Send,

§

impl<W> Sync for Writer<W>
where W: Sync,

§

impl<W> Unpin for Writer<W>
where W: Unpin,

§

impl<W> UnwindSafe for Writer<W>
where W: UnwindSafe,

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.