Trait spacetimedb_sats::de::Deserializer
source · pub trait Deserializer<'de>: Sized {
type Error: Error;
Show 22 methods
// Required methods
fn deserialize_product<V: ProductVisitor<'de>>(
self,
visitor: V
) -> Result<V::Output, Self::Error>;
fn deserialize_sum<V: SumVisitor<'de>>(
self,
visitor: V
) -> Result<V::Output, Self::Error>;
fn deserialize_bool(self) -> Result<bool, Self::Error>;
fn deserialize_u8(self) -> Result<u8, Self::Error>;
fn deserialize_u16(self) -> Result<u16, Self::Error>;
fn deserialize_u32(self) -> Result<u32, Self::Error>;
fn deserialize_u64(self) -> Result<u64, Self::Error>;
fn deserialize_u128(self) -> Result<u128, Self::Error>;
fn deserialize_i8(self) -> Result<i8, Self::Error>;
fn deserialize_i16(self) -> Result<i16, Self::Error>;
fn deserialize_i32(self) -> Result<i32, Self::Error>;
fn deserialize_i64(self) -> Result<i64, Self::Error>;
fn deserialize_i128(self) -> Result<i128, Self::Error>;
fn deserialize_f32(self) -> Result<f32, Self::Error>;
fn deserialize_f64(self) -> Result<f64, Self::Error>;
fn deserialize_str<V: SliceVisitor<'de, str>>(
self,
visitor: V
) -> Result<V::Output, Self::Error>;
fn deserialize_bytes<V: SliceVisitor<'de, [u8]>>(
self,
visitor: V
) -> Result<V::Output, Self::Error>;
fn deserialize_array_seed<V: ArrayVisitor<'de, T::Output>, T: DeserializeSeed<'de> + Clone>(
self,
visitor: V,
seed: T
) -> Result<V::Output, Self::Error>;
fn deserialize_map_seed<Vi: MapVisitor<'de, K::Output, V::Output>, K: DeserializeSeed<'de> + Clone, V: DeserializeSeed<'de> + Clone>(
self,
visitor: Vi,
kseed: K,
vseed: V
) -> Result<Vi::Output, Self::Error>;
// Provided methods
fn deserialize_str_slice(self) -> Result<&'de str, Self::Error> { ... }
fn deserialize_array<V: ArrayVisitor<'de, T>, T: Deserialize<'de>>(
self,
visitor: V
) -> Result<V::Output, Self::Error> { ... }
fn deserialize_map<Vi: MapVisitor<'de, K, V>, K: Deserialize<'de>, V: Deserialize<'de>>(
self,
visitor: Vi
) -> Result<Vi::Output, Self::Error> { ... }
}
Expand description
A data format that can deserialize any data structure supported by SATS.
The Deserializer
trait in SATS performs the same function as serde::Deserializer
in serde
.
See the documentation of serde::Deserializer
for more information of the data model.
Implementations of Deserialize
map themselves into this data model
by passing to the Deserializer
a visitor that can receive the necessary types.
The kind of visitor depends on the deserialize_*
method.
Unlike in Serde, there isn’t a single monolithic Visitor
trait,
but rather, this functionality is split up into more targeted traits such as SumVisitor<'de>
.
The lifetime 'de
allows us to deserialize lifetime-generic types in a zero-copy fashion.
Required Associated Types§
Required Methods§
sourcefn deserialize_product<V: ProductVisitor<'de>>(
self,
visitor: V
) -> Result<V::Output, Self::Error>
fn deserialize_product<V: ProductVisitor<'de>>( self, visitor: V ) -> Result<V::Output, Self::Error>
Deserializes a product value from the input.
sourcefn deserialize_sum<V: SumVisitor<'de>>(
self,
visitor: V
) -> Result<V::Output, Self::Error>
fn deserialize_sum<V: SumVisitor<'de>>( self, visitor: V ) -> Result<V::Output, Self::Error>
Deserializes a sum value from the input.
The entire process of deserializing a sum, starting from deserialize(args...)
, is roughly:
-
deserialize
calls this method,deserialize_sum(sum_visitor)
, providing us with asum_visitor
. -
This method calls
sum_visitor.visit_sum(sum_access)
, wheresum_access
deals with extracting the tag and the variant data, with the latter provided asVariantAccess
). TheSumVisitor
will then assemble these into the representation of a sum value that theDeserialize
implementation wants. -
visit_sum
then callssum_access.variant(variant_visitor)
, and uses the providedvariant_visitor
to translate extracted variant names / tags into something that is meaningful forvisit_sum
, e.g., an index.The call to
variant
will also returnvariant_access
that can deserialize the contents of the variant. -
Finally, after
variant
returns,visit_sum
deserializes the variant data usingvariant_access.deserialize_seed(seed)
orvariant_access.deserialize()
. This part may require some conditional logic depending on the identified variant.
The data format will also return an object (VariantAccess
)
that can deserialize the contents of the variant.
sourcefn deserialize_bool(self) -> Result<bool, Self::Error>
fn deserialize_bool(self) -> Result<bool, Self::Error>
Deserializes a bool
value from the input.
sourcefn deserialize_u8(self) -> Result<u8, Self::Error>
fn deserialize_u8(self) -> Result<u8, Self::Error>
Deserializes a u8
value from the input.
sourcefn deserialize_u16(self) -> Result<u16, Self::Error>
fn deserialize_u16(self) -> Result<u16, Self::Error>
Deserializes a u16
value from the input.
sourcefn deserialize_u32(self) -> Result<u32, Self::Error>
fn deserialize_u32(self) -> Result<u32, Self::Error>
Deserializes a u32
value from the input.
sourcefn deserialize_u64(self) -> Result<u64, Self::Error>
fn deserialize_u64(self) -> Result<u64, Self::Error>
Deserializes a u64
value from the input.
sourcefn deserialize_u128(self) -> Result<u128, Self::Error>
fn deserialize_u128(self) -> Result<u128, Self::Error>
Deserializes a u128
value from the input.
sourcefn deserialize_i8(self) -> Result<i8, Self::Error>
fn deserialize_i8(self) -> Result<i8, Self::Error>
Deserializes an `i8 value from the input.
sourcefn deserialize_i16(self) -> Result<i16, Self::Error>
fn deserialize_i16(self) -> Result<i16, Self::Error>
Deserializes an `i16 value from the input.
sourcefn deserialize_i32(self) -> Result<i32, Self::Error>
fn deserialize_i32(self) -> Result<i32, Self::Error>
Deserializes an `i32 value from the input.
sourcefn deserialize_i64(self) -> Result<i64, Self::Error>
fn deserialize_i64(self) -> Result<i64, Self::Error>
Deserializes an `i64 value from the input.
sourcefn deserialize_i128(self) -> Result<i128, Self::Error>
fn deserialize_i128(self) -> Result<i128, Self::Error>
Deserializes an `i128 value from the input.
sourcefn deserialize_f32(self) -> Result<f32, Self::Error>
fn deserialize_f32(self) -> Result<f32, Self::Error>
Deserializes an `f32 value from the input.
sourcefn deserialize_f64(self) -> Result<f64, Self::Error>
fn deserialize_f64(self) -> Result<f64, Self::Error>
Deserializes an `f64 value from the input.
sourcefn deserialize_str<V: SliceVisitor<'de, str>>(
self,
visitor: V
) -> Result<V::Output, Self::Error>
fn deserialize_str<V: SliceVisitor<'de, str>>( self, visitor: V ) -> Result<V::Output, Self::Error>
Deserializes a string-like object the input.
sourcefn deserialize_bytes<V: SliceVisitor<'de, [u8]>>(
self,
visitor: V
) -> Result<V::Output, Self::Error>
fn deserialize_bytes<V: SliceVisitor<'de, [u8]>>( self, visitor: V ) -> Result<V::Output, Self::Error>
Deserializes a byte slice-like value.
sourcefn deserialize_array_seed<V: ArrayVisitor<'de, T::Output>, T: DeserializeSeed<'de> + Clone>(
self,
visitor: V,
seed: T
) -> Result<V::Output, Self::Error>
fn deserialize_array_seed<V: ArrayVisitor<'de, T::Output>, T: DeserializeSeed<'de> + Clone>( self, visitor: V, seed: T ) -> Result<V::Output, Self::Error>
Deserializes an array value.
The deserialization is provided with a seed
value.
sourcefn deserialize_map_seed<Vi: MapVisitor<'de, K::Output, V::Output>, K: DeserializeSeed<'de> + Clone, V: DeserializeSeed<'de> + Clone>(
self,
visitor: Vi,
kseed: K,
vseed: V
) -> Result<Vi::Output, Self::Error>
fn deserialize_map_seed<Vi: MapVisitor<'de, K::Output, V::Output>, K: DeserializeSeed<'de> + Clone, V: DeserializeSeed<'de> + Clone>( self, visitor: Vi, kseed: K, vseed: V ) -> Result<Vi::Output, Self::Error>
Deserializes a map value.
The deserialization is provided with kseed
and vseed
for keys and values respectively.
Provided Methods§
sourcefn deserialize_str_slice(self) -> Result<&'de str, Self::Error>
fn deserialize_str_slice(self) -> Result<&'de str, Self::Error>
Deserializes an &str
string value.
sourcefn deserialize_array<V: ArrayVisitor<'de, T>, T: Deserialize<'de>>(
self,
visitor: V
) -> Result<V::Output, Self::Error>
fn deserialize_array<V: ArrayVisitor<'de, T>, T: Deserialize<'de>>( self, visitor: V ) -> Result<V::Output, Self::Error>
Deserializes an array value.
This is typically the same as deserialize_array_seed
with an uninteresting seed
value.
sourcefn deserialize_map<Vi: MapVisitor<'de, K, V>, K: Deserialize<'de>, V: Deserialize<'de>>(
self,
visitor: Vi
) -> Result<Vi::Output, Self::Error>
fn deserialize_map<Vi: MapVisitor<'de, K, V>, K: Deserialize<'de>, V: Deserialize<'de>>( self, visitor: Vi ) -> Result<Vi::Output, Self::Error>
Deserializes a map value.
This is typically the same as deserialize_map_seed
with an uninteresting seed
value.