Struct MapValueDeserializer

Source
struct MapValueDeserializer<'de, 'd, 'm, R, E>
where R: XmlRead<'de>, E: EntityResolver,
{ map: &'m mut ElementMapAccess<'de, 'd, R, E>, fixed_name: bool, }
Expand description

A deserializer for a value of map or struct. That deserializer slightly differently processes events for a primitive types and sequences than a Deserializer.

This deserializer used to deserialize two kinds of fields:

  • usual fields with a dedicated name, such as field_one or field_two, in that case field Self::fixed_name is true;
  • the special $value field which represents any tag or a textual content in the XML which would be found in the document, in that case field Self::fixed_name is false.

This deserializer can see two kind of events at the start:

which represents two possible variants of items:

<item>A tag item</item>
A text item
<yet another="tag item"/>

This deserializer are very similar to a ElementDeserializer. The only difference in the deserialize_seq method. This deserializer will act as an iterator over tags / text within it’s parent tag, whereas the ElementDeserializer will represent sequences as an xs:list.

This deserializer processes items as following:

  • primitives (numbers, booleans, strings, characters) are deserialized either from a text content, or unwrapped from a one level of a tag. So, 123 and <int>123</int> both can be deserialized into an u32;
  • Option:
    • empty text of DeEvent::Text is deserialized as None;
    • everything else are deserialized as Some using the same deserializer, including <tag/> or <tag></tag>;
  • units (()) and unit structs consumes the whole text or element subtree;
  • newtype structs are deserialized by forwarding deserialization of inner type with the same deserializer;
  • sequences, tuples and tuple structs are deserialized by iterating within the parent tag and deserializing each tag or text content using ElementDeserializer;
  • structs and maps are deserialized using new instance of ElementMapAccess;
  • enums:
    • in case of DeEvent::Text event the text content is deserialized as a $text variant. Enum content is deserialized from the text using SimpleTypeDeserializer;
    • in case of DeEvent::Start event the tag name is deserialized as an enum tag, and the content inside are deserialized as an enum content. Depending on a variant kind deserialization is performed as:
      • unit variants: consuming text content or a subtree;
      • newtype variants: forward deserialization to the inner type using this deserializer;
      • tuple variants: call deserialize_tuple of this deserializer;
      • struct variants: call deserialize_struct of this deserializer.

Fields§

§map: &'m mut ElementMapAccess<'de, 'd, R, E>

Access to the map that created this deserializer. Gives access to the context, such as list of fields, that current map known about.

§fixed_name: bool

Whether this deserializer was created for deserialization from an element with fixed name, or the elements with different names or even text are allowed.

If this field is true, we process <tag> element in the following XML shape:

<any-tag>
  <tag>...</tag>
</any-tag>

The whole map represented by an <any-tag> element, the map key is a tag, and the value starts with is a Start("tag") (the value deserializer will see that event first) and extended to the matching End("tag") event. In order to deserialize primitives (such as usize) we need to allow to look inside the one levels of tags, so the

<tag>42<tag>

could be deserialized into 42usize without problems, and at the same time

<tag>
  <key1/>
  <key2/>
  <!--...-->
<tag>

could be deserialized to a struct.

If this field is false, we processes the one of following XML shapes:

<any-tag>
  text value
</any-tag>
<any-tag>
  <![CDATA[cdata value]]>
</any-tag>
<any-tag>
  <any>...</any>
</any-tag>

The whole map represented by an <any-tag> element, the map key is implicit and equals to the VALUE_KEY constant, and the value is a Text, or a Start event (the value deserializer will see one of those events). In the first two cases the value of this field do not matter (because we already see the textual event and there no reasons to look “inside” something), but in the last case the primitives should raise a deserialization error, because that means that you trying to deserialize the following struct:

struct AnyName {
  #[serde(rename = "$value")]
  any_name: String,
}

which means that any_name should get a content of the <any-tag> element.

Changing this can be valuable for https://github.com/tafia/quick-xml/issues/383, but those fields should be explicitly marked that they want to get any possible markup as a String and that mark is different from marking them as accepting “text content” which the currently $text means.

Implementations§

Source§

impl<'de, 'd, 'm, R, E> MapValueDeserializer<'de, 'd, 'm, R, E>
where R: XmlRead<'de>, E: EntityResolver,

Source

fn read_string(&mut self) -> Result<Cow<'de, str>, DeError>

Returns a next string as concatenated content of consequent Text and CData events, used inside deserialize_primitives!().

Trait Implementations§

Source§

impl<'de, 'd, 'm, R, E> Deserializer<'de> for MapValueDeserializer<'de, 'd, 'm, R, E>
where R: XmlRead<'de>, E: EntityResolver,

Source§

fn deserialize_char<V>(self, visitor: V) -> Result<V::Value, DeError>
where V: Visitor<'de>,

Character represented as strings.

Source§

fn deserialize_string<V>(self, visitor: V) -> Result<V::Value, DeError>
where V: Visitor<'de>,

Representation of owned strings the same as non-owned.

Source§

fn deserialize_bytes<V>(self, visitor: V) -> Result<V::Value, DeError>
where V: Visitor<'de>,

Forwards deserialization to the deserialize_any.

Source§

fn deserialize_byte_buf<V>(self, visitor: V) -> Result<V::Value, DeError>
where V: Visitor<'de>,

Forwards deserialization to the deserialize_bytes.

Source§

fn deserialize_unit_struct<V>( self, _name: &'static str, visitor: V, ) -> Result<V::Value, DeError>
where V: Visitor<'de>,

Representation of the named units the same as unnamed units.

Source§

fn deserialize_tuple<V>( self, _len: usize, visitor: V, ) -> Result<V::Value, DeError>
where V: Visitor<'de>,

Representation of tuples the same as sequences.

Source§

fn deserialize_tuple_struct<V>( self, _name: &'static str, len: usize, visitor: V, ) -> Result<V::Value, DeError>
where V: Visitor<'de>,

Representation of named tuples the same as unnamed tuples.

Source§

fn deserialize_map<V>(self, visitor: V) -> Result<V::Value, DeError>
where V: Visitor<'de>,

Forwards deserialization to the deserialize_struct with empty name and fields.

Source§

fn deserialize_identifier<V>(self, visitor: V) -> Result<V::Value, DeError>
where V: Visitor<'de>,

Identifiers represented as strings.

Source§

fn deserialize_ignored_any<V>(self, visitor: V) -> Result<V::Value, DeError>
where V: Visitor<'de>,

Forwards deserialization to the deserialize_unit.

Source§

fn deserialize_newtype_struct<V>( self, _name: &'static str, visitor: V, ) -> Result<V::Value, Self::Error>
where V: Visitor<'de>,

Forwards deserialization of the inner type. Always calls Visitor::visit_newtype_struct with the same deserializer.

Source§

fn deserialize_seq<V>(self, visitor: V) -> Result<V::Value, Self::Error>
where V: Visitor<'de>,

Deserializes each <tag> in

<any-tag>
  <tag>...</tag>
  <tag>...</tag>
  <tag>...</tag>
</any-tag>

as a sequence item, where <any-tag> represents a Map in a Self::map, and a <tag> is a sequential field of that map.

Source§

type Error = DeError

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

fn deserialize_i8<V>(self, visitor: V) -> Result<V::Value, DeError>
where V: Visitor<'de>,

Hint that the Deserialize type is expecting an i8 value.
Source§

fn deserialize_i16<V>(self, visitor: V) -> Result<V::Value, DeError>
where V: Visitor<'de>,

Hint that the Deserialize type is expecting an i16 value.
Source§

fn deserialize_i32<V>(self, visitor: V) -> Result<V::Value, DeError>
where V: Visitor<'de>,

Hint that the Deserialize type is expecting an i32 value.
Source§

fn deserialize_i64<V>(self, visitor: V) -> Result<V::Value, DeError>
where V: Visitor<'de>,

Hint that the Deserialize type is expecting an i64 value.
Source§

fn deserialize_u8<V>(self, visitor: V) -> Result<V::Value, DeError>
where V: Visitor<'de>,

Hint that the Deserialize type is expecting a u8 value.
Source§

fn deserialize_u16<V>(self, visitor: V) -> Result<V::Value, DeError>
where V: Visitor<'de>,

Hint that the Deserialize type is expecting a u16 value.
Source§

fn deserialize_u32<V>(self, visitor: V) -> Result<V::Value, DeError>
where V: Visitor<'de>,

Hint that the Deserialize type is expecting a u32 value.
Source§

fn deserialize_u64<V>(self, visitor: V) -> Result<V::Value, DeError>
where V: Visitor<'de>,

Hint that the Deserialize type is expecting a u64 value.
Source§

fn deserialize_i128<V>(self, visitor: V) -> Result<V::Value, DeError>
where V: Visitor<'de>,

Hint that the Deserialize type is expecting an i128 value. Read more
Source§

fn deserialize_u128<V>(self, visitor: V) -> Result<V::Value, DeError>
where V: Visitor<'de>,

Hint that the Deserialize type is expecting an u128 value. Read more
Source§

fn deserialize_f32<V>(self, visitor: V) -> Result<V::Value, DeError>
where V: Visitor<'de>,

Hint that the Deserialize type is expecting a f32 value.
Source§

fn deserialize_f64<V>(self, visitor: V) -> Result<V::Value, DeError>
where V: Visitor<'de>,

Hint that the Deserialize type is expecting a f64 value.
Source§

fn deserialize_bool<V>(self, visitor: V) -> Result<V::Value, DeError>
where V: Visitor<'de>,

Hint that the Deserialize type is expecting a bool value.
Source§

fn deserialize_str<V>(self, visitor: V) -> Result<V::Value, DeError>
where V: Visitor<'de>,

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

fn deserialize_unit<V>(self, visitor: V) -> Result<V::Value, Self::Error>
where V: Visitor<'de>,

Hint that the Deserialize type is expecting a unit value.
Source§

fn deserialize_option<V>(self, visitor: V) -> Result<V::Value, Self::Error>
where V: Visitor<'de>,

Hint that the Deserialize type is expecting an optional value. Read more
Source§

fn deserialize_struct<V>( self, name: &'static str, fields: &'static [&'static str], visitor: V, ) -> Result<V::Value, Self::Error>
where V: Visitor<'de>,

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

fn deserialize_enum<V>( self, _name: &'static str, _variants: &'static [&'static str], visitor: V, ) -> Result<V::Value, Self::Error>
where V: Visitor<'de>,

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

fn deserialize_any<V>(self, visitor: V) -> Result<V::Value, Self::Error>
where V: Visitor<'de>,

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

fn is_human_readable(&self) -> bool

Determine whether Deserialize implementations should expect to deserialize their human-readable form. Read more
Source§

impl<'de, 'd, 'm, R, E> EnumAccess<'de> for MapValueDeserializer<'de, 'd, 'm, R, E>
where R: XmlRead<'de>, E: EntityResolver,

Source§

type Error = DeError

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

type Variant = MapValueVariantAccess<'de, 'd, 'm, R, E>

The Visitor that will be used to deserialize the content of the enum variant.
Source§

fn variant_seed<V>( self, seed: V, ) -> Result<(V::Value, Self::Variant), Self::Error>
where V: DeserializeSeed<'de>,

variant is called to identify which variant to deserialize. Read more
Source§

fn variant<V>(self) -> Result<(V, Self::Variant), Self::Error>
where V: Deserialize<'de>,

variant is called to identify which variant to deserialize. Read more

Auto Trait Implementations§

§

impl<'de, 'd, 'm, R, E> Freeze for MapValueDeserializer<'de, 'd, 'm, R, E>

§

impl<'de, 'd, 'm, R, E> !RefUnwindSafe for MapValueDeserializer<'de, 'd, 'm, R, E>

§

impl<'de, 'd, 'm, R, E> Send for MapValueDeserializer<'de, 'd, 'm, R, E>
where R: Send, E: Send,

§

impl<'de, 'd, 'm, R, E> Sync for MapValueDeserializer<'de, 'd, 'm, R, E>
where R: Sync, E: Sync,

§

impl<'de, 'd, 'm, R, E> Unpin for MapValueDeserializer<'de, 'd, 'm, R, E>

§

impl<'de, 'd, 'm, R, E> !UnwindSafe for MapValueDeserializer<'de, 'd, 'm, R, E>

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.