Skip to main content

Chunk

Enum Chunk 

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

A chunk represents the minimum state necessary to serialize a value.

Chunks are of two types: atomic primitives and stateful emitters. For instance Chunk::Bool(true) is an atomic primitive. It can be emitted to a serializer directly. On the other hand a Chunk::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 serialization with Chunk::seq, Chunk::map and Chunk::structure (see Boxed).

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 chunk. This is useful to serialize a value by converting it into another value first as the handle can own that value:

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

struct Point(u32, u32);

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

The container_shape of the value that returned the chunk 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 chunk.

Forwarding chunks cannot be flattened into structs.

Implementations§

Source§

impl<'a> Chunk<'a>

Source

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

Creates a chunk of a sequence emitter in the arena of the serialization.

Source

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

Creates a chunk of a map emitter in the arena of the serialization.

Source

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

Creates a chunk of a struct emitter in the arena of the serialization.

Trait Implementations§

Source§

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

Source§

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

Converts to this type from the input type.
Source§

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

Source§

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

Converts to this type from the input type.
Source§

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

Source§

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

Converts to this type from the input type.
Source§

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

Source§

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

Converts to this type from the input type.
Source§

impl From<String> for Chunk<'static>

Source§

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

Converts to this type from the input type.
Source§

impl From<bool> for Chunk<'static>

Source§

fn from(value: bool) -> Self

Converts to this type from the input type.
Source§

impl From<char> for Chunk<'static>

Source§

fn from(value: char) -> Self

Converts to this type from the input type.
Source§

impl From<f32> for Chunk<'static>

Source§

fn from(value: f32) -> Self

Converts to this type from the input type.
Source§

impl From<f64> for Chunk<'static>

Source§

fn from(value: f64) -> Self

Converts to this type from the input type.
Source§

impl From<i64> for Chunk<'static>

Source§

fn from(value: i64) -> Self

Converts to this type from the input type.
Source§

impl From<isize> for Chunk<'static>

Source§

fn from(value: isize) -> Self

Converts to this type from the input type.
Source§

impl From<u64> for Chunk<'static>

Source§

fn from(value: u64) -> Self

Converts to this type from the input type.
Source§

impl From<usize> for Chunk<'static>

Source§

fn from(value: usize) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

impl<'a> Freeze for Chunk<'a>

§

impl<'a> Send for Chunk<'a>

§

impl<'a> UnsafeUnpin for Chunk<'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.