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] hasserde_yaml::Deserializer: serde::Deserializer serde_jsonhas&mut serde_json::Deserializer: serde::Deserializer
Required Associated Types§
Sourcetype DeserializerStorage
type DeserializerStorage
Stack storage for the deserializer.
type Deserializer<'storage>: Deserializer<'de, Error = Self::Error> where 'de: 'storage
Required Methods§
Sourcefn recreate_deserializer_storage(&mut self) -> Self::DeserializerStorage
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.
Sourcefn use_deserializer_from_storage(
storage: &mut Option<Self::DeserializerStorage>,
) -> Self::Deserializer<'_>
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.
impl<'de, T: Borrow<str> + ?Sized> Source<'de> for JsonStr<'de, T>
serde_json only.type DeserializerStorage = Deserializer<StrRead<'de>>
type Deserializer<'storage> = &'storage mut Deserializer<StrRead<'de>> where 'de: 'storage
type Error = Error
Source§impl<'de, T: Borrow<[u8]> + ?Sized> Source<'de> for JsonBytes<'de, T>
Available on crate feature serde_json only.
impl<'de, T: Borrow<[u8]> + ?Sized> Source<'de> for JsonBytes<'de, T>
serde_json only.