Skip to main content

Writer

Struct Writer 

pub struct Writer { /* private fields */ }
Expand description

A buffer values are written to. Reuse one to keep the allocation.

Implementations§

§

impl Writer

pub fn new() -> Writer

Creates an empty writer with no byte limit.

pub fn clear(&mut self)

Empties it, keeping its allocation and resetting any per-call error and byte limit.

pub fn replace(&mut self, buffer: Vec<u8>)

Takes buffer as its storage, emptied, resetting the error and byte limit.

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

The bytes written, leaving the writer’s storage to the caller.

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

Borrows the bytes written so far; check error before sending them.

pub fn limit(&mut self, max_bytes: usize)

Bound this call’s encoded bytes. A refusal is recorded before any growth or copy. A new writer has no limit; clear and replace remove it.

pub fn put_bytes(&mut self, bytes: &[u8])

Appends raw bytes without a length prefix.

pub fn put_str(&mut self, text: &str)

A string: its length, then its bytes.

pub fn put_len(&mut self, len: usize)

A length or count.

pub fn put_opt<T>(&mut self, value: Option<&T>)
where T: Put + ?Sized,

An optional borrowed value, written as the Option it stands for.

pub fn put<T>(&mut self, value: &T)
where T: Put + ?Sized,

Encodes a borrowed value unless an earlier write failed.

pub fn put_owned<T>(&mut self, value: T)
where T: Wire,

Transfers owned resources while leaving plain data on the normal zero-copy path.

pub fn nested(&mut self, write: impl FnOnce(&mut Writer))

Writes one structural level, refusing before recursing past MAX_DEPTH.

pub fn error(&self) -> Option<WireError>

The first encoding failure; callers refuse the call rather than sending partial bytes.

pub fn fail(&mut self, error: WireError)

Records the first failure, preventing subsequent writes.

Trait Implementations§

§

impl Default for Writer

§

fn default() -> Writer

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.