Trait unbase::util::serde::Deserializer [] [src]

pub trait Deserializer {
    type Error: Error;
    fn deserialize<V>(
        self,
        visitor: V
    ) -> Result<<V as Visitor>::Value, Self::Error>
    where
        V: Visitor
;
fn deserialize_bool<V>(
        self,
        visitor: V
    ) -> Result<<V as Visitor>::Value, Self::Error>
    where
        V: Visitor
;
fn deserialize_u8<V>(
        self,
        visitor: V
    ) -> Result<<V as Visitor>::Value, Self::Error>
    where
        V: Visitor
;
fn deserialize_u16<V>(
        self,
        visitor: V
    ) -> Result<<V as Visitor>::Value, Self::Error>
    where
        V: Visitor
;
fn deserialize_u32<V>(
        self,
        visitor: V
    ) -> Result<<V as Visitor>::Value, Self::Error>
    where
        V: Visitor
;
fn deserialize_u64<V>(
        self,
        visitor: V
    ) -> Result<<V as Visitor>::Value, Self::Error>
    where
        V: Visitor
;
fn deserialize_i8<V>(
        self,
        visitor: V
    ) -> Result<<V as Visitor>::Value, Self::Error>
    where
        V: Visitor
;
fn deserialize_i16<V>(
        self,
        visitor: V
    ) -> Result<<V as Visitor>::Value, Self::Error>
    where
        V: Visitor
;
fn deserialize_i32<V>(
        self,
        visitor: V
    ) -> Result<<V as Visitor>::Value, Self::Error>
    where
        V: Visitor
;
fn deserialize_i64<V>(
        self,
        visitor: V
    ) -> Result<<V as Visitor>::Value, Self::Error>
    where
        V: Visitor
;
fn deserialize_f32<V>(
        self,
        visitor: V
    ) -> Result<<V as Visitor>::Value, Self::Error>
    where
        V: Visitor
;
fn deserialize_f64<V>(
        self,
        visitor: V
    ) -> Result<<V as Visitor>::Value, Self::Error>
    where
        V: Visitor
;
fn deserialize_char<V>(
        self,
        visitor: V
    ) -> Result<<V as Visitor>::Value, Self::Error>
    where
        V: Visitor
;
fn deserialize_str<V>(
        self,
        visitor: V
    ) -> Result<<V as Visitor>::Value, Self::Error>
    where
        V: Visitor
;
fn deserialize_string<V>(
        self,
        visitor: V
    ) -> Result<<V as Visitor>::Value, Self::Error>
    where
        V: Visitor
;
fn deserialize_bytes<V>(
        self,
        visitor: V
    ) -> Result<<V as Visitor>::Value, Self::Error>
    where
        V: Visitor
;
fn deserialize_byte_buf<V>(
        self,
        visitor: V
    ) -> Result<<V as Visitor>::Value, Self::Error>
    where
        V: Visitor
;
fn deserialize_option<V>(
        self,
        visitor: V
    ) -> Result<<V as Visitor>::Value, Self::Error>
    where
        V: Visitor
;
fn deserialize_unit<V>(
        self,
        visitor: V
    ) -> Result<<V as Visitor>::Value, Self::Error>
    where
        V: Visitor
;
fn deserialize_unit_struct<V>(
        self,
        name: &'static str,
        visitor: V
    ) -> Result<<V as Visitor>::Value, Self::Error>
    where
        V: Visitor
;
fn deserialize_newtype_struct<V>(
        self,
        name: &'static str,
        visitor: V
    ) -> Result<<V as Visitor>::Value, Self::Error>
    where
        V: Visitor
;
fn deserialize_seq<V>(
        self,
        visitor: V
    ) -> Result<<V as Visitor>::Value, Self::Error>
    where
        V: Visitor
;
fn deserialize_seq_fixed_size<V>(
        self,
        len: usize,
        visitor: V
    ) -> Result<<V as Visitor>::Value, Self::Error>
    where
        V: Visitor
;
fn deserialize_tuple<V>(
        self,
        len: usize,
        visitor: V
    ) -> Result<<V as Visitor>::Value, Self::Error>
    where
        V: Visitor
;
fn deserialize_tuple_struct<V>(
        self,
        name: &'static str,
        len: usize,
        visitor: V
    ) -> Result<<V as Visitor>::Value, Self::Error>
    where
        V: Visitor
;
fn deserialize_map<V>(
        self,
        visitor: V
    ) -> Result<<V as Visitor>::Value, Self::Error>
    where
        V: Visitor
;
fn deserialize_struct<V>(
        self,
        name: &'static str,
        fields: &'static [&'static str],
        visitor: V
    ) -> Result<<V as Visitor>::Value, Self::Error>
    where
        V: Visitor
;
fn deserialize_struct_field<V>(
        self,
        visitor: V
    ) -> Result<<V as Visitor>::Value, Self::Error>
    where
        V: Visitor
;
fn deserialize_enum<V>(
        self,
        name: &'static str,
        variants: &'static [&'static str],
        visitor: V
    ) -> Result<<V as Visitor>::Value, Self::Error>
    where
        V: Visitor
;
fn deserialize_ignored_any<V>(
        self,
        visitor: V
    ) -> Result<<V as Visitor>::Value, Self::Error>
    where
        V: Visitor
; }

A data format that can deserialize any data structure supported by Serde.

The role of this trait is to define the deserialization half of the Serde data model, which is a way to categorize every Rust data type into one of 28 possible types. Each method of the Serializer trait corresponds to one of the types of the data model.

Implementations of Deserialize map themselves into this data model by passing to the Deserializer a Visitor implementation that can receive these various types.

The types that make up the Serde data model are:

  • 12 primitive types:
    • bool
    • i8, i16, i32, i64
    • u8, u16, u32, u64
    • f32, f64
    • char
  • string
  • byte array - [u8]
  • option
    • either none or some value
  • unit
    • unit is the type of () in Rust
  • unit_struct
    • for example struct Unit or PhantomData<T>
  • unit_variant
    • the E::A and E::B in enum E { A, B }
  • newtype_struct
    • for example struct Millimeters(u8)
  • newtype_variant
    • the E::N in enum E { N(u8) }
  • seq
    • a dynamically sized sequence of values, for example Vec<T> or HashSet<T>
  • seq_fixed_size
    • a statically sized sequence of values for which the size will be known at deserialization time without looking at the serialized data, for example [u64; 10]
  • tuple
    • for example (u8,) or (String, u64, Vec<T>)
  • tuple_struct
    • for example struct Rgb(u8, u8, u8)
  • tuple_variant
    • the E::T in enum E { T(u8, u8) }
  • map
    • for example BTreeMap<K, V>
  • struct
    • a key-value pairing in which the keys will be known at deserialization time without looking at the serialized data, for example struct S { r: u8, g: u8, b: u8 }
  • struct_variant
    • the E::S in enum E { S { r: u8, g: u8, b: u8 } }

The Deserializer trait supports two entry point styles which enables different kinds of deserialization.

  1. The deserialize method. Self-describing data formats like JSON are able to look at the serialized data and tell what it represents. For example the JSON deserializer may see an opening curly brace ({) and know that it is seeing a map. If the data format supports Deserializer::deserialize, it will drive the Visitor using whatever type it sees in the input. JSON uses this approach when deserializing serde_json::Value which is an enum that can represent any JSON document. Without knowing what is in a JSON document, we can deserialize it to serde_json::Value by going through Deserializer::deserialize.

  2. The various deserialize_* methods. Non-self-describing formats like Bincode need to be told what is in the input in order to deserialize it. The deserialize_* methods are hints to the deserializer for how to interpret the next piece of input. Non-self-describing formats are not able to deserialize something like serde_json::Value which relies on Deserializer::deserialize.

When implementing Deserialize, you should avoid relying on Deserializer::deserialize unless you need to be told by the Deserializer what type is in the input. Know that relying on Deserializer::deserialize means your data type will be able to deserialize from self-describing formats only, ruling out Bincode and many others.

Associated Types

The error type that can be returned if some error occurs during deserialization.

Required Methods

Require the Deserializer to figure out how to drive the visitor based on what data type is in the input.

When implementing Deserialize, you should avoid relying on Deserializer::deserialize unless you need to be told by the Deserializer what type is in the input. Know that relying on Deserializer::deserialize means your data type will be able to deserialize from self-describing formats only, ruling out Bincode and many others.

Hint that the Deserialize type is expecting a bool value.

Hint that the Deserialize type is expecting a u8 value.

Hint that the Deserialize type is expecting a u16 value.

Hint that the Deserialize type is expecting a u32 value.

Hint that the Deserialize type is expecting a u64 value.

Hint that the Deserialize type is expecting an i8 value.

Hint that the Deserialize type is expecting an i16 value.

Hint that the Deserialize type is expecting an i32 value.

Hint that the Deserialize type is expecting an i64 value.

Hint that the Deserialize type is expecting a f32 value.

Hint that the Deserialize type is expecting a f64 value.

Hint that the Deserialize type is expecting a char value.

Hint that the Deserialize type is expecting a string value and does not benefit from taking ownership of buffered data owned by the Deserializer.

If the Visitor would benefit from taking ownership of String data, indiciate this to the Deserializer by using deserialize_string instead.

Hint that the Deserialize type is expecting a string value and would benefit from taking ownership of buffered data owned by the Deserializer.

If the Visitor would not benefit from taking ownership of String data, indicate that to the Deserializer by using deserialize_str instead.

Hint that the Deserialize type is expecting a byte array and does not benefit from taking ownership of buffered data owned by the Deserializer.

If the Visitor would benefit from taking ownership of Vec<u8> data, indicate this to the Deserializer by using deserialize_byte_buf instead.

Hint that the Deserialize type is expecting a byte array and would benefit from taking ownership of buffered data owned by the Deserializer.

If the Visitor would not benefit from taking ownership of Vec<u8> data, indicate that to the Deserializer by using deserialize_bytes instead.

Hint that the Deserialize type is expecting an optional value.

This allows deserializers that encode an optional value as a nullable value to convert the null value into None and a regular value into Some(value).

Hint that the Deserialize type is expecting a unit value.

Hint that the Deserialize type is expecting a unit struct with a particular name.

Hint that the Deserialize type is expecting a newtype struct with a particular name.

Hint that the Deserialize type is expecting a sequence of values.

Hint that the Deserialize type is expecting a sequence of values and knows how many values there are without looking at the serialized data.

Hint that the Deserialize type is expecting a tuple value with a particular number of elements.

Hint that the Deserialize type is expecting a tuple struct with a particular name and number of fields.

Hint that the Deserialize type is expecting a map of key-value pairs.

Hint that the Deserialize type is expecting a struct with a particular name and fields.

Hint that the Deserialize type is expecting the name of a struct field.

Hint that the Deserialize type is expecting an enum value with a particular name and possible variants.

Hint that the Deserialize type needs to deserialize a value whose type doesn't matter because it is ignored.

Deserializers for non-self-describing formats may not support this mode.

Implementations on Foreign Types

impl<E> Deserializer for BoolDeserializer<E> where
    E: Error
[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

impl<E> Deserializer for UsizeDeserializer<E> where
    E: Error
[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

impl<E> Deserializer for IsizeDeserializer<E> where
    E: Error
[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

impl<E> Deserializer for U16Deserializer<E> where
    E: Error
[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

impl<'a, E> Deserializer for StrDeserializer<'a, E> where
    E: Error
[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

impl<E> Deserializer for ByteBufDeserializer<E> where
    E: Error
[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

impl<E> Deserializer for StringDeserializer<E> where
    E: Error
[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

impl<E> Deserializer for I8Deserializer<E> where
    E: Error
[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

impl<E> Deserializer for I64Deserializer<E> where
    E: Error
[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

impl<E> Deserializer for F32Deserializer<E> where
    E: Error
[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

impl<'a, E> Deserializer for BytesDeserializer<'a, E> where
    E: Error
[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

impl<E> Deserializer for UnitDeserializer<E> where
    E: Error
[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

impl<E> Deserializer for U8Deserializer<E> where
    E: Error
[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

impl<'a, E> Deserializer for CowStrDeserializer<'a, E> where
    E: Error
[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

impl<I, T, E> Deserializer for SeqDeserializer<I, E> where
    E: Error,
    I: Iterator<Item = T>,
    T: ValueDeserializer<E>, 
[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

impl<E> Deserializer for CharDeserializer<E> where
    E: Error
[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

impl<I, E> Deserializer for MapDeserializer<I, E> where
    E: Error,
    I: Iterator,
    <I as Iterator>::Item: Pair,
    <<I as Iterator>::Item as Pair>::First: ValueDeserializer<E>,
    <<I as Iterator>::Item as Pair>::Second: ValueDeserializer<E>, 
[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

impl<E> Deserializer for F64Deserializer<E> where
    E: Error
[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

impl<E> Deserializer for U64Deserializer<E> where
    E: Error
[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

impl<E> Deserializer for I16Deserializer<E> where
    E: Error
[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

impl<V_, E> Deserializer for SeqVisitorDeserializer<V_, E> where
    E: Error,
    V_: SeqVisitor<Error = E>, 
[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

impl<V_, E> Deserializer for MapVisitorDeserializer<V_, E> where
    E: Error,
    V_: MapVisitor<Error = E>, 
[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

impl<E> Deserializer for U32Deserializer<E> where
    E: Error
[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

impl<E> Deserializer for I32Deserializer<E> where
    E: Error
[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

impl<'a, R> Deserializer for &'a mut Deserializer<R> where
    R: Read
[src]

[src]

[src]

Parses a null as a None, and any other values as a Some(...).

[src]

Parses a newtype struct as the underlying value.

[src]

Parses an enum as an object like {"$KEY":$VALUE}, where $VALUE is either a straight value, a [..], or a {..}.

[src]

Parses a JSON string as bytes. Note that this function does not check whether the bytes represent valid unicode code points.

The JSON specification requires that strings only contain valid unicode characters. To deal with non-conforming JSON, you may use this function, which attempts to parse a string without checking whether the bytes represent valid unicode code points.

Escape sequences are processed as usual, and for \uXXXX escapes it is still checked if the hex number represents a valid unicode code point.

Example usage

You can use this to parse JSON strings containing non-unicode bytes:

let bytes = serde::bytes::ByteBuf::from(b"some raw bytes: \xe5\x00\xe5".to_vec());
let parsed = serde_json::from_slice(  b"\"some raw bytes: \xe5\x00\xe5\"").unwrap();
 
assert_eq!(bytes, parsed);

\u escape sequences with invalid unicode code points still fail to parse:

let json = "\"invalid unicode surrogate: \\uD801\"";
let parsed: Result<serde::bytes::ByteBuf, _> = serde_json::from_str(json);
assert!(parsed.is_err(), "{} should not parse: {:?}", json, parsed);

[src]

impl Deserializer for Value
[src]

[src]

[src]

[src]

[src]

impl<'a> Deserializer for &'a Number
[src]

[src]

impl Deserializer for Number
[src]

[src]

impl<'a> Deserializer for &'a Value
[src]

[src]

[src]

[src]

[src]

Implementors