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_oneorfield_two, in that case fieldSelf::fixed_nameistrue; - the special
$valuefield which represents any tag or a textual content in the XML which would be found in the document, in that case fieldSelf::fixed_nameisfalse.
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,
123and<int>123</int>both can be deserialized into anu32; Option:- empty text of
DeEvent::Textis deserialized asNone; - everything else are deserialized as
Someusing the same deserializer, including<tag/>or<tag></tag>;
- empty text of
- 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::Textevent the text content is deserialized as a$textvariant. Enum content is deserialized from the text usingSimpleTypeDeserializer; - in case of
DeEvent::Startevent 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_tupleof this deserializer; - struct variants: call
deserialize_structof this deserializer.
- in case of
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: boolWhether 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,
impl<'de, 'd, 'm, R, E> MapValueDeserializer<'de, 'd, 'm, R, E>where
R: XmlRead<'de>,
E: EntityResolver,
Sourcefn read_string(&mut self) -> Result<Cow<'de, str>, DeError>
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,
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>,
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>,
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>,
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>,
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>,
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>,
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>,
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>,
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>,
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>,
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>,
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>,
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
type Error = DeError
Source§fn deserialize_i8<V>(self, visitor: V) -> Result<V::Value, DeError>where
V: Visitor<'de>,
fn deserialize_i8<V>(self, visitor: V) -> Result<V::Value, DeError>where
V: Visitor<'de>,
Deserialize type is expecting an i8 value.Source§fn deserialize_i16<V>(self, visitor: V) -> Result<V::Value, DeError>where
V: Visitor<'de>,
fn deserialize_i16<V>(self, visitor: V) -> Result<V::Value, DeError>where
V: Visitor<'de>,
Deserialize type is expecting an i16 value.Source§fn deserialize_i32<V>(self, visitor: V) -> Result<V::Value, DeError>where
V: Visitor<'de>,
fn deserialize_i32<V>(self, visitor: V) -> Result<V::Value, DeError>where
V: Visitor<'de>,
Deserialize type is expecting an i32 value.Source§fn deserialize_i64<V>(self, visitor: V) -> Result<V::Value, DeError>where
V: Visitor<'de>,
fn deserialize_i64<V>(self, visitor: V) -> Result<V::Value, DeError>where
V: Visitor<'de>,
Deserialize type is expecting an i64 value.Source§fn deserialize_u8<V>(self, visitor: V) -> Result<V::Value, DeError>where
V: Visitor<'de>,
fn deserialize_u8<V>(self, visitor: V) -> Result<V::Value, DeError>where
V: Visitor<'de>,
Deserialize type is expecting a u8 value.Source§fn deserialize_u16<V>(self, visitor: V) -> Result<V::Value, DeError>where
V: Visitor<'de>,
fn deserialize_u16<V>(self, visitor: V) -> Result<V::Value, DeError>where
V: Visitor<'de>,
Deserialize type is expecting a u16 value.Source§fn deserialize_u32<V>(self, visitor: V) -> Result<V::Value, DeError>where
V: Visitor<'de>,
fn deserialize_u32<V>(self, visitor: V) -> Result<V::Value, DeError>where
V: Visitor<'de>,
Deserialize type is expecting a u32 value.Source§fn deserialize_u64<V>(self, visitor: V) -> Result<V::Value, DeError>where
V: Visitor<'de>,
fn deserialize_u64<V>(self, visitor: V) -> Result<V::Value, DeError>where
V: Visitor<'de>,
Deserialize type is expecting a u64 value.Source§fn deserialize_f32<V>(self, visitor: V) -> Result<V::Value, DeError>where
V: Visitor<'de>,
fn deserialize_f32<V>(self, visitor: V) -> Result<V::Value, DeError>where
V: Visitor<'de>,
Deserialize type is expecting a f32 value.Source§fn deserialize_f64<V>(self, visitor: V) -> Result<V::Value, DeError>where
V: Visitor<'de>,
fn deserialize_f64<V>(self, visitor: V) -> Result<V::Value, DeError>where
V: Visitor<'de>,
Deserialize type is expecting a f64 value.Source§fn deserialize_bool<V>(self, visitor: V) -> Result<V::Value, DeError>where
V: Visitor<'de>,
fn deserialize_bool<V>(self, visitor: V) -> Result<V::Value, DeError>where
V: Visitor<'de>,
Deserialize type is expecting a bool value.Source§fn deserialize_str<V>(self, visitor: V) -> Result<V::Value, DeError>where
V: Visitor<'de>,
fn deserialize_str<V>(self, visitor: V) -> Result<V::Value, DeError>where
V: Visitor<'de>,
Deserialize type is expecting a string value and does
not benefit from taking ownership of buffered data owned by the
Deserializer. Read moreSource§fn deserialize_unit<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
fn deserialize_unit<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
Deserialize type is expecting a unit value.Source§fn deserialize_option<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
fn deserialize_option<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
Deserialize type is expecting an optional value. Read moreSource§fn deserialize_struct<V>(
self,
name: &'static str,
fields: &'static [&'static str],
visitor: V,
) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
fn deserialize_struct<V>(
self,
name: &'static str,
fields: &'static [&'static str],
visitor: V,
) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
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>,
fn deserialize_enum<V>(
self,
_name: &'static str,
_variants: &'static [&'static str],
visitor: V,
) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
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>,
fn deserialize_any<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
Deserializer to figure out how to drive the visitor based
on what data type is in the input. Read moreSource§fn is_human_readable(&self) -> bool
fn is_human_readable(&self) -> bool
Deserialize implementations should expect to
deserialize their human-readable form. Read moreSource§impl<'de, 'd, 'm, R, E> EnumAccess<'de> for MapValueDeserializer<'de, 'd, 'm, R, E>where
R: XmlRead<'de>,
E: EntityResolver,
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
type Error = DeError
Source§type Variant = MapValueVariantAccess<'de, 'd, 'm, R, E>
type Variant = MapValueVariantAccess<'de, 'd, 'm, R, E>
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>,
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