Trait MapAccess

Source
pub trait MapAccess<'de> {
    type Error: Error;

    // Required methods
    fn next_key_seed<K>(
        &mut self,
        seed: K,
    ) -> Result<Option<<K as DeserializeSeed<'de>>::Value>, Self::Error>
       where K: DeserializeSeed<'de>;
    fn next_value_seed<V>(
        &mut self,
        seed: V,
    ) -> Result<<V as DeserializeSeed<'de>>::Value, Self::Error>
       where V: DeserializeSeed<'de>;

    // Provided methods
    fn next_entry_seed<K, V>(
        &mut self,
        kseed: K,
        vseed: V,
    ) -> Result<Option<(<K as DeserializeSeed<'de>>::Value, <V as DeserializeSeed<'de>>::Value)>, Self::Error>
       where K: DeserializeSeed<'de>,
             V: DeserializeSeed<'de> { ... }
    fn next_key<K>(&mut self) -> Result<Option<K>, Self::Error>
       where K: Deserialize<'de> { ... }
    fn next_value<V>(&mut self) -> Result<V, Self::Error>
       where V: Deserialize<'de> { ... }
    fn next_entry<K, V>(&mut self) -> Result<Option<(K, V)>, Self::Error>
       where K: Deserialize<'de>,
             V: Deserialize<'de> { ... }
    fn size_hint(&self) -> Option<usize> { ... }
}
Expand description

Provides a Visitor access to each entry of a map in the input.

This is a trait that a Deserializer passes to a Visitor implementation.

ยงLifetime

The 'de lifetime of this trait is the lifetime of data that may be borrowed by deserialized map entries. See the page Understanding deserializer lifetimes for a more detailed explanation of these lifetimes.

ยงExample implementation

The example data format presented on the website demonstrates an implementation of MapAccess for a basic JSON data format.

Required Associated Typesยง

Source

type Error: Error

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

Required Methodsยง

Source

fn next_key_seed<K>( &mut self, seed: K, ) -> Result<Option<<K as DeserializeSeed<'de>>::Value>, Self::Error>
where K: DeserializeSeed<'de>,

This returns Ok(Some(key)) for the next key in the map, or Ok(None) if there are no more remaining entries.

Deserialize implementations should typically use MapAccess::next_key or MapAccess::next_entry instead.

Source

fn next_value_seed<V>( &mut self, seed: V, ) -> Result<<V as DeserializeSeed<'de>>::Value, Self::Error>
where V: DeserializeSeed<'de>,

This returns a Ok(value) for the next value in the map.

Deserialize implementations should typically use MapAccess::next_value instead.

ยงPanics

Calling next_value_seed before next_key_seed is incorrect and is allowed to panic or return bogus results.

Provided Methodsยง

Source

fn next_entry_seed<K, V>( &mut self, kseed: K, vseed: V, ) -> Result<Option<(<K as DeserializeSeed<'de>>::Value, <V as DeserializeSeed<'de>>::Value)>, Self::Error>
where K: DeserializeSeed<'de>, V: DeserializeSeed<'de>,

This returns Ok(Some((key, value))) for the next (key-value) pair in the map, or Ok(None) if there are no more remaining items.

MapAccess implementations should override the default behavior if a more efficient implementation is possible.

Deserialize implementations should typically use MapAccess::next_entry instead.

Source

fn next_key<K>(&mut self) -> Result<Option<K>, Self::Error>
where K: Deserialize<'de>,

This returns Ok(Some(key)) for the next key in the map, or Ok(None) if there are no more remaining entries.

This method exists as a convenience for Deserialize implementations. MapAccess implementations should not override the default behavior.

Source

fn next_value<V>(&mut self) -> Result<V, Self::Error>
where V: Deserialize<'de>,

This returns a Ok(value) for the next value in the map.

This method exists as a convenience for Deserialize implementations. MapAccess implementations should not override the default behavior.

ยงPanics

Calling next_value before next_key is incorrect and is allowed to panic or return bogus results.

Source

fn next_entry<K, V>(&mut self) -> Result<Option<(K, V)>, Self::Error>
where K: Deserialize<'de>, V: Deserialize<'de>,

This returns Ok(Some((key, value))) for the next (key-value) pair in the map, or Ok(None) if there are no more remaining items.

This method exists as a convenience for Deserialize implementations. MapAccess implementations should not override the default behavior.

Source

fn size_hint(&self) -> Option<usize>

Returns the number of entries remaining in the map, if known.

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.

Implementations on Foreign Typesยง

ยง

impl<'de> MapAccess<'de> for QsDeserializer<'de>

ยง

type Error = Error

ยง

fn next_key_seed<K>( &mut self, seed: K, ) -> Result<Option<<K as DeserializeSeed<'de>>::Value>, Error>
where K: DeserializeSeed<'de>,

ยง

fn next_value_seed<V>( &mut self, seed: V, ) -> Result<<V as DeserializeSeed<'de>>::Value, Error>
where V: DeserializeSeed<'de>,

Sourceยง

impl<'de, A> MapAccess<'de> for &mut A
where A: MapAccess<'de> + ?Sized,

Sourceยง

type Error = <A as MapAccess<'de>>::Error

Sourceยง

fn next_key_seed<K>( &mut self, seed: K, ) -> Result<Option<<K as DeserializeSeed<'de>>::Value>, <&mut A as MapAccess<'de>>::Error>
where K: DeserializeSeed<'de>,

Sourceยง

fn next_value_seed<V>( &mut self, seed: V, ) -> Result<<V as DeserializeSeed<'de>>::Value, <&mut A as MapAccess<'de>>::Error>
where V: DeserializeSeed<'de>,

Sourceยง

fn next_entry_seed<K, V>( &mut self, kseed: K, vseed: V, ) -> Result<Option<(<K as DeserializeSeed<'de>>::Value, <V as DeserializeSeed<'de>>::Value)>, <&mut A as MapAccess<'de>>::Error>
where K: DeserializeSeed<'de>, V: DeserializeSeed<'de>,

Sourceยง

fn next_entry<K, V>( &mut self, ) -> Result<Option<(K, V)>, <&mut A as MapAccess<'de>>::Error>
where K: Deserialize<'de>, V: Deserialize<'de>,

Sourceยง

fn next_key<K>( &mut self, ) -> Result<Option<K>, <&mut A as MapAccess<'de>>::Error>
where K: Deserialize<'de>,

Sourceยง

fn next_value<V>(&mut self) -> Result<V, <&mut A as MapAccess<'de>>::Error>
where V: Deserialize<'de>,

Sourceยง

fn size_hint(&self) -> Option<usize>

ยง

impl<'de, E> MapAccess<'de> for DatetimeDeserializer<E>
where E: Error,

ยง

type Error = E

ยง

fn next_key_seed<K>( &mut self, seed: K, ) -> Result<Option<<K as DeserializeSeed<'de>>::Value>, <DatetimeDeserializer<E> as MapAccess<'de>>::Error>
where K: DeserializeSeed<'de>,

ยง

fn next_value_seed<V>( &mut self, seed: V, ) -> Result<<V as DeserializeSeed<'de>>::Value, <DatetimeDeserializer<E> as MapAccess<'de>>::Error>
where V: DeserializeSeed<'de>,

ยง

impl<'de, T, E> MapAccess<'de> for SpannedDeserializer<'de, T, E>
where T: IntoDeserializer<'de, E>, E: Error,

ยง

type Error = E

ยง

fn next_key_seed<K>( &mut self, seed: K, ) -> Result<Option<<K as DeserializeSeed<'de>>::Value>, <SpannedDeserializer<'de, T, E> as MapAccess<'de>>::Error>
where K: DeserializeSeed<'de>,

ยง

fn next_value_seed<V>( &mut self, seed: V, ) -> Result<<V as DeserializeSeed<'de>>::Value, <SpannedDeserializer<'de, T, E> as MapAccess<'de>>::Error>
where V: DeserializeSeed<'de>,

Implementorsยง

Sourceยง

impl<'de, I, E> MapAccess<'de> for MapDeserializer<'de, I, E>
where I: Iterator, <I as Iterator>::Item: Pair, <<I as Iterator>::Item as Pair>::First: IntoDeserializer<'de, E>, <<I as Iterator>::Item as Pair>::Second: IntoDeserializer<'de, E>, E: Error,