Skip to main content

FormatDeserializer

Struct FormatDeserializer 

Source
pub struct FormatDeserializer<'parser, 'input, const BORROW: bool> { /* private fields */ }
Expand description

Generic deserializer that drives a format-specific parser directly into Partial.

The const generic BORROW controls whether string data can be borrowed:

  • BORROW=true: strings without escapes are borrowed from input
  • BORROW=false: all strings are owned

The lifetime 'parser is the lifetime of the parser itself, which may be shorter than 'input (e.g., for streaming parsers that produce owned data but contain references to internal state).

Implementations§

Source§

impl<'parser, 'input, const BORROW: bool> FormatDeserializer<'parser, 'input, BORROW>

Source

pub fn deserialize_into( &mut self, wip: Partial<'input, BORROW>, meta: MetaSource<'input>, ) -> Result<Partial<'input, BORROW>, DeserializeError>

Main deserialization entry point - deserialize into a Partial.

Uses the precomputed DeserStrategy from TypePlan for fast dispatch. The strategy is computed once at Partial allocation time, eliminating repeated runtime inspection of Shape/Def/vtable during deserialization.

The meta parameter specifies where metadata should come from:

  • MetaSource::Explicit(meta) - use provided metadata from outer context
  • MetaSource::FromEvents - read fresh metadata from the events being parsed
Source

pub fn deserialize_into_with_shape( &mut self, wip: Partial<'input, BORROW>, hint_shape: &'static Shape, ) -> Result<Partial<'input, BORROW>, DeserializeError>

Deserialize using an explicit source shape for parser hints.

This walks hint_shape for control flow and parser hints, but builds into the wip Partial (which should be a DynamicValue like Value).

Source§

impl<'parser, 'input> FormatDeserializer<'parser, 'input, true>

Source

pub fn new(parser: &'parser mut dyn FormatParser<'input>) -> Self

Create a new deserializer that can borrow strings from input.

Source

pub fn with_buffer_capacity( parser: &'parser mut dyn FormatParser<'input>, buffer_capacity: usize, ) -> Self

Create a new deserializer with a custom buffer capacity.

Source§

impl<'parser, 'input> FormatDeserializer<'parser, 'input, false>

Source

pub fn new_owned(parser: &'parser mut dyn FormatParser<'input>) -> Self

Create a new deserializer that produces owned strings.

Source

pub fn with_buffer_capacity_owned( parser: &'parser mut dyn FormatParser<'input>, buffer_capacity: usize, ) -> Self

Create a new deserializer with a custom buffer capacity.

Source§

impl<'parser, 'input, const BORROW: bool> FormatDeserializer<'parser, 'input, BORROW>

Source

pub fn parser_mut(&mut self) -> &mut dyn FormatParser<'input>

Borrow the inner parser mutably.

Source§

impl<'parser, 'input> FormatDeserializer<'parser, 'input, true>

Source

pub fn deserialize<T>(&mut self) -> Result<T, DeserializeError>
where T: Facet<'input>,

Deserialize the next value in the stream into T, allowing borrowed strings.

Source

pub fn deserialize_root<T>(&mut self) -> Result<T, DeserializeError>
where T: Facet<'input>,

Deserialize the next value in the stream into T (for backward compatibility).

Source

pub fn deserialize_deferred<T>(&mut self) -> Result<T, DeserializeError>
where T: Facet<'input>,

Deserialize using deferred mode, allowing interleaved field initialization.

This is required for formats like TOML that allow table reopening, where fields of a nested struct may be set, then fields of a sibling, then more fields of the original struct.

Source§

impl<'parser, 'input> FormatDeserializer<'parser, 'input, false>

Source

pub fn deserialize<T>(&mut self) -> Result<T, DeserializeError>
where T: Facet<'static>,

Deserialize the next value in the stream into T, using owned strings.

Source

pub fn deserialize_root<T>(&mut self) -> Result<T, DeserializeError>
where T: Facet<'static>,

Deserialize the next value in the stream into T (for backward compatibility).

Source

pub fn deserialize_deferred<T>(&mut self) -> Result<T, DeserializeError>
where T: Facet<'static>,

Deserialize using deferred mode, allowing interleaved field initialization.

This is required for formats like TOML that allow table reopening, where fields of a nested struct may be set, then fields of a sibling, then more fields of the original struct.

Source

pub fn deserialize_with_shape<T>( &mut self, source_shape: &'static Shape, ) -> Result<T, DeserializeError>
where T: Facet<'static>,

Deserialize using an explicit source shape for parser hints.

This is useful for non-self-describing formats like postcard where you need to decode data that was serialized using a specific type, but you only have the shape information at runtime (not the concrete type).

The target type T should typically be a DynamicValue like facet_value::Value.

Auto Trait Implementations§

§

impl<'parser, 'input, const BORROW: bool> Freeze for FormatDeserializer<'parser, 'input, BORROW>

§

impl<'parser, 'input, const BORROW: bool> !RefUnwindSafe for FormatDeserializer<'parser, 'input, BORROW>

§

impl<'parser, 'input, const BORROW: bool> !Send for FormatDeserializer<'parser, 'input, BORROW>

§

impl<'parser, 'input, const BORROW: bool> !Sync for FormatDeserializer<'parser, 'input, BORROW>

§

impl<'parser, 'input, const BORROW: bool> Unpin for FormatDeserializer<'parser, 'input, BORROW>

§

impl<'parser, 'input, const BORROW: bool> UnsafeUnpin for FormatDeserializer<'parser, 'input, BORROW>

§

impl<'parser, 'input, const BORROW: bool> !UnwindSafe for FormatDeserializer<'parser, 'input, BORROW>

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.