Skip to main content

Emit

Enum Emit 

Source
pub enum Emit<'a> {
    Atom(Atom<'a>),
    Struct(Boxed<dyn StructEmitter + 'a>),
    Map(Boxed<dyn MapEmitter + 'a>),
    Seq(Boxed<dyn SeqEmitter + 'a>),
    Forward(SerializeHandle<'a>),
}
Expand description

Describes how a value is emitted, returned by Serialize::serialize.

A value is either emitted as an atom, by a stateful emitter or by forwarding to another value. For instance Emit::Atom(Atom::Bool(true)) is emitted to a serializer directly. On the other hand an Emit::Map contains a stateful emitter that keeps yielding values until it’s done walking over the map.

The emitters are typically allocated in the arena of the state with Emit::seq, Emit::map and Emit::structure (see Boxed). They are the serialization equivalent of the Sinks of deserialization: they hold the state of a value that is being serialized.

Variants§

§

Atom(Atom<'a>)

§

Struct(Boxed<dyn StructEmitter + 'a>)

§

Map(Boxed<dyn MapEmitter + 'a>)

§

Seq(Boxed<dyn SeqEmitter + 'a>)

§

Forward(SerializeHandle<'a>)

Serializes another value in place of this one.

The driver serializes the value in the handle as if it was produced instead of the value that returned the Emit. This is useful to serialize a value by converting it into another value first as the handle can own that value:

use deser::ser::{Emit, Serialize, SerializeHandle};
use deser::{Error, State};

struct Point(u32, u32);

impl Serialize for Point {
    fn serialize<'a>(value: &'a Self, state: &mut State) -> Result<Emit<'a>, Error> {
        // serialize as a vector
        Ok(Emit::Forward(SerializeHandle::arena(
            vec![value.0, value.1],
            state,
        )))
    }
}

The container_shape of the value that returned the Emit is not used, the forwarded value provides its own. finish is invoked on the forwarded value first and then on the value that returned the Emit.

Values that forward cannot be flattened into structs.

Implementations§

Source§

impl<'a> Emit<'a>

Source

pub fn seq<E: SeqEmitter + 'a>(emitter: E, state: &mut State) -> Emit<'a>

Emits a sequence with an emitter in the arena of the serialization.

Source

pub fn map<E: MapEmitter + 'a>(emitter: E, state: &mut State) -> Emit<'a>

Emits a map with an emitter in the arena of the state.

Source

pub fn structure<E: StructEmitter + 'a>( emitter: E, state: &mut State, ) -> Emit<'a>

Emits a struct with an emitter in the arena of the serialization.

Trait Implementations§

Source§

impl<'a> From<&'a [u8]> for Emit<'a>

Source§

fn from(value: &'a [u8]) -> Emit<'a>

Converts to this type from the input type.
Source§

impl<'a> From<&'a str> for Emit<'a>

Source§

fn from(value: &'a str) -> Emit<'a>

Converts to this type from the input type.
Source§

impl From<()> for Emit<'static>

Source§

fn from(_: ()) -> Emit<'static>

Converts to this type from the input type.
Source§

impl<'a> From<Atom<'a>> for Emit<'a>

Source§

fn from(atom: Atom<'a>) -> Self

Converts to this type from the input type.
Source§

impl From<String> for Emit<'static>

Source§

fn from(value: String) -> Emit<'static>

Converts to this type from the input type.
Source§

impl From<bool> for Emit<'static>

Source§

fn from(value: bool) -> Self

Converts to this type from the input type.
Source§

impl From<char> for Emit<'static>

Source§

fn from(value: char) -> Self

Converts to this type from the input type.
Source§

impl From<f32> for Emit<'static>

Source§

fn from(value: f32) -> Self

Converts to this type from the input type.
Source§

impl From<f64> for Emit<'static>

Source§

fn from(value: f64) -> Self

Converts to this type from the input type.
Source§

impl From<i64> for Emit<'static>

Source§

fn from(value: i64) -> Self

Converts to this type from the input type.
Source§

impl From<isize> for Emit<'static>

Source§

fn from(value: isize) -> Self

Converts to this type from the input type.
Source§

impl From<u64> for Emit<'static>

Source§

fn from(value: u64) -> Self

Converts to this type from the input type.
Source§

impl From<usize> for Emit<'static>

Source§

fn from(value: usize) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl<'a> !RefUnwindSafe for Emit<'a>

§

impl<'a> !Sync for Emit<'a>

§

impl<'a> !Unpin for Emit<'a>

§

impl<'a> !UnwindSafe for Emit<'a>

§

impl<'a> Freeze for Emit<'a>

§

impl<'a> Send for Emit<'a>

§

impl<'a> UnsafeUnpin for Emit<'a>

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.