Trait Source

Source
pub trait Source<'de> {
    type DeserializerStorage;
    type Deserializer<'storage>: Deserializer<'de, Error = Self::Error>
       where 'de: 'storage;
    type Error: Error;

    // Required methods
    fn recreate_deserializer_storage(&mut self) -> Self::DeserializerStorage;
    fn use_deserializer_from_storage(
        storage: &mut Option<Self::DeserializerStorage>,
    ) -> Self::Deserializer<'_>;
}
Expand description

Describes a resource that can be deserialized multiple times: a Deserializer together with the data it works on, such as a string reference or byte slice.

For instance, crate::source::JsonStr is a borrowed string that we should use serde_json on.

For your own data format, take a look at the implementation of either JsonStr and [YamlStr] — depending on whether your data format implements Deserializer like serde_json or like [serde_yaml]:

  • [serde_yaml] has serde_yaml::Deserializer: serde::Deserializer
  • serde_json has &mut serde_json::Deserializer: serde::Deserializer

Required Associated Types§

Source

type DeserializerStorage

Stack storage for the deserializer.

Source

type Deserializer<'storage>: Deserializer<'de, Error = Self::Error> where 'de: 'storage

Source

type Error: Error

The error type cannot depend on 'storage.

Required Methods§

Source

fn recreate_deserializer_storage(&mut self) -> Self::DeserializerStorage

Recreate a deserializer for this source.

Every deserializer created from a source should behave exactly the same.

If end of file happens in a map in between the key and the value, then our first go at deserializing will fail, and we have to recreate a new deserializer for the same source.

Source

fn use_deserializer_from_storage( storage: &mut Option<Self::DeserializerStorage>, ) -> Self::Deserializer<'_>

Will be called exactly once per Self::DeserializerStorage. The argument is guaranteed to be Some.

Typically returns either storage.take() or &mut storage.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<'de, T: Borrow<str> + ?Sized> Source<'de> for JsonStr<'de, T>

Available on crate feature serde_json only.
Source§

type DeserializerStorage = Deserializer<StrRead<'de>>

Source§

type Deserializer<'storage> = &'storage mut Deserializer<StrRead<'de>> where 'de: 'storage

Source§

type Error = Error

Source§

impl<'de, T: Borrow<[u8]> + ?Sized> Source<'de> for JsonBytes<'de, T>

Available on crate feature serde_json only.
Source§

type DeserializerStorage = Deserializer<SliceRead<'de>>

Source§

type Deserializer<'storage> = &'storage mut Deserializer<SliceRead<'de>> where 'de: 'storage

Source§

type Error = Error