Skip to main content

Writer

Struct Writer 

Source
pub struct Writer<'b> { /* private fields */ }
Expand description

A cursor that writes SML values into a caller-provided buffer.

Used by the tests and simulators; a meter readout client never needs it.

Debug shows the position and capacity, never the bytes.

Implementations§

Source§

impl<'b> Writer<'b>

Source

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

A writer at the start of buf.

Source

pub const fn position(&self) -> usize

Bytes written so far.

Source

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

The bytes written so far.

Source

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

Write raw bytes.

Source

pub fn tl(&mut self, kind: Kind, len: usize) -> Result<()>

Write a type-length field. len is the element count for a list and the number of data bytes otherwise.

Source

pub fn list(&mut self, n: usize) -> Result<()>

Write a list header.

Source

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

Write an octet string.

Source

pub fn absent(&mut self) -> Result<()>

Write the absent-field marker.

Source

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

Write a boolean.

Source

pub fn unsigned(&mut self, v: u64, width: usize) -> Result<()>

Write an unsigned integer in exactly width bytes (1, 2, 4 or 8 for the SML types Unsigned8 to Unsigned64).

Source

pub fn integer(&mut self, v: i64, width: usize) -> Result<()>

Write a signed integer in exactly width bytes.

Source

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

Write an unsigned integer in the smallest of 1, 2, 4 or 8 bytes that holds it.

Source

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

Write a signed integer in the smallest of 1, 2, 4 or 8 bytes that holds it.

Source

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

Write an optional octet string: the absent marker for None.

Source

pub fn end_of_message(&mut self) -> Result<()>

Write the end-of-message marker.

Trait Implementations§

Source§

impl Debug for Writer<'_>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'b> !UnwindSafe for Writer<'b>

§

impl<'b> Forget for Writer<'b>

§

impl<'b> Freeze for Writer<'b>
where &'b mut [u8]: Freeze,

§

impl<'b> Move for Writer<'b>

§

impl<'b> RefUnwindSafe for Writer<'b>

§

impl<'b> Send for Writer<'b>

§

impl<'b> Sync for Writer<'b>

§

impl<'b> Unpin for Writer<'b>
where &'b mut [u8]: Unpin,

§

impl<'b> UnsafeUnpin for Writer<'b>
where &'b 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.