Skip to main content

SerializeHandle

Struct SerializeHandle 

Source
pub struct SerializeHandle<'a>(/* private fields */);
Expand description

A handle to a value that is serialized.

During serialization it’s common to be in a situation where one needs to return a locally constructed Serialize. This is where SerializeHandle comes in. The handle either borrows the value (see to and SerializeRef) or owns it (see arena and heap).

Unlike the SinkHandle of deserialization, which holds a sink that is already deserializing a value, this holds a value that is not serialized yet. The serialization equivalent of a sink is an emitter in a Emit. The constructors line up: to borrows, arena and heap own in the same way for both handles.

Implementations§

Source§

impl<'a> SerializeHandle<'a>

Source

pub fn to<S: Serialize>(value: &'a S) -> SerializeHandle<'a>

Creates a borrowed handle to a value.

Source

pub fn arena<S: Serialize + Send + 'a>( value: S, state: &mut State, ) -> SerializeHandle<'a>

Creates an owned handle to a value in the arena of the state.

This is how owned values are typically created (for instance for Emit::Forward), see Boxed.

Source

pub fn heap<S: Serialize + Send + 'a>(value: S) -> SerializeHandle<'a>

Creates an owned handle to a value on the heap.

Unlike arena the value does not need a state and is independent of any serialization.

Source

pub fn get(&self) -> SerializeRef<'_>

Returns a reference to the value.

Trait Implementations§

Source§

impl Debug for SerializeHandle<'_>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<'a> From<SerializeRef<'a>> for SerializeHandle<'a>

Source§

fn from(value: SerializeRef<'a>) -> SerializeHandle<'a>

Converts to this type from the input type.
Source§

impl Serialize for SerializeHandle<'_>

Source§

fn serialize<'b>(value: &'b Self, state: &mut State) -> Result<Emit<'b>, Error>

Serializes the value.
Source§

fn finish(value: &Self, state: &mut State) -> Result<(), Error>

Invoked after the serialization finished. Read more
Source§

fn is_optional(value: &Self) -> bool

Checks if the value represents an optional value. Read more
Source§

fn container_shape(value: &Self) -> ContainerShape

Returns the shape of the value if it’s a map or sequence. Read more
Source§

fn describe(value: &Self, d: &mut dyn Describe)

Describes the Rust shape of the value. Read more

Auto Trait Implementations§

§

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

§

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

§

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

§

impl<'a> Freeze for SerializeHandle<'a>

§

impl<'a> Send for SerializeHandle<'a>

§

impl<'a> Sync for SerializeHandle<'a>

§

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