Encoder

Struct Encoder 

Source
pub struct Encoder<W: Write> { /* private fields */ }

Implementations§

Source§

impl<W: Write> Encoder<W>

Source

pub fn new(w: W) -> Self

Create an encoder.

Source

pub fn write_null(&mut self) -> Result<Offset>

Source

pub fn write_bool(&mut self, b: bool) -> Result<Offset>

Source

pub fn write_i64(&mut self, n: i64) -> Result<Offset>

Write an integer.

Source

pub fn write_ref(&mut self, p: Offset) -> Result<Offset>

Source

pub fn write_pointer(&mut self, p: Offset) -> Result<Offset>

Source

pub fn write_f32(&mut self, f: f32) -> Result<Offset>

Source

pub fn write_f64(&mut self, f: f64) -> Result<Offset>

Source

pub fn write_string(&mut self, s: &str) -> Result<Offset>

Write a unicode string.

Source

pub fn write_bytes(&mut self, b: &[u8]) -> Result<Offset>

Write a binary blob.

Source

pub fn write_variant0(&mut self, c: VariantIdx) -> Result<Offset>

Write a nullary variant.

Source

pub fn write_immediate(&mut self, imm: Immediate<'_>) -> Result<Offset>

Write an immediate value.

Source

pub fn write_immediate_or_return_pointer( &mut self, imm: Immediate<'_>, ) -> Result<Offset>

Write the immediate; but if it’s a pointer, return the pointer without writing a thing.

Source

pub fn write_tag(&mut self, tag: Tag, v: Immediate<'_>) -> Result<Offset>

Source

pub fn write_array(&mut self, arr: &[Immediate<'_>]) -> Result<Offset>

Write an array.

The values in the array must be converted to immediates already, possibly by way of writing them first and making pointers to their written representation.

Source

pub fn write_map( &mut self, map: &[(Immediate<'_>, Immediate<'_>)], ) -> Result<Offset>

Write a map. Keys and values must already be encoded into immediates.

Source

pub fn write_variant( &mut self, c: VariantIdx, args: &[Immediate<'_>], ) -> Result<Immediate<'static>>

Write a variant c with arguments args.

Source

pub fn finalize(self, entrypoint: Immediate<'_>) -> Result<()>

Write the postfix to point to entrypoint, and consume the encoder.

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

§

impl<W> UnwindSafe for Encoder<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.