pub trait MapKeyAccess<'de>: Sized {
type Error: Error;
type Value: MapValueAccess<'de, Error = Self::Error, Key = Self>;
// Required method
fn next_key_seed<S>(
self,
seed: S,
) -> Result<Option<(S::Value, Self::Value)>, Self::Error>
where S: DeserializeSeed<'de>;
// Provided methods
fn next_key<T>(self) -> Result<Option<(T, Self::Value)>, Self::Error>
where T: Deserialize<'de> { ... }
fn next_entry_seed<K, V>(
self,
kseed: K,
vseed: V,
) -> Result<Option<((K::Value, V::Value), Option<Self>)>, Self::Error>
where K: DeserializeSeed<'de>,
V: DeserializeSeed<'de> { ... }
fn next_entry<K, V>(
self,
) -> Result<Option<((K, V), Option<Self>)>, Self::Error>
where K: Deserialize<'de>,
V: Deserialize<'de>,
Self::Value: MapValueAccess<'de, Error = Self::Error> { ... }
fn size_hint(&self) -> Option<usize> { ... }
}Expand description
Move-oriented version of serde::de::MapAccess, for getting keys.
This trait gets around a lot of the shortcomings of serde’s MapAccess by
using a move-oriented interface:
- It’s not possible to call
next_keyafter a previous call tonext_keyreturnedOk(None). - Accessing the value associated with a key is moved to a different trait,
which is returned from
next_key. By splitting key-access and value-access into different traits, we can ensure thatnext_keyandnext_valuecan never be called out of order, removing the need for potential panics (and the associated state tracking between keys and values).
This trait otherwise is identical to its serde counterpart and serves the same
purpose; see those docs for details (though note that accessing values is
handled separately through the MapValueAccess trait.)
Use AccessAdapter to convert this type to a serde::de::SeqAccess to pass
into visit_seq.
Required Associated Types§
Sourcetype Value: MapValueAccess<'de, Error = Self::Error, Key = Self>
type Value: MapValueAccess<'de, Error = Self::Error, Key = Self>
The value accessor associated with this key accessor. A call to
next_key that returns a key will also return a Value
object, which can be used to retrieve the value associated with that key.
Required Methods§
Sourcefn next_key_seed<S>(
self,
seed: S,
) -> Result<Option<(S::Value, Self::Value)>, Self::Error>where
S: DeserializeSeed<'de>,
fn next_key_seed<S>(
self,
seed: S,
) -> Result<Option<(S::Value, Self::Value)>, Self::Error>where
S: DeserializeSeed<'de>,
This returns Ok(Some((key, value_access))) for the next key in the
map, or Ok(None) if there are no more entries. The returned
value_access object can be used to retrieve the value associated
with this key.
The seed allows for passing data into a Deserialize implementation
at runtime; typically it makes more sense to call next_key.
Provided Methods§
Sourcefn next_key<T>(self) -> Result<Option<(T, Self::Value)>, Self::Error>where
T: Deserialize<'de>,
fn next_key<T>(self) -> Result<Option<(T, Self::Value)>, Self::Error>where
T: Deserialize<'de>,
This returns Ok(Some((key, value_access))) for the next key in the
map, or Ok(None) if there are no more entries. The returned
value_access can be used to retrieve the value associated with this
key.
Sourcefn next_entry_seed<K, V>(
self,
kseed: K,
vseed: V,
) -> Result<Option<((K::Value, V::Value), Option<Self>)>, Self::Error>where
K: DeserializeSeed<'de>,
V: DeserializeSeed<'de>,
fn next_entry_seed<K, V>(
self,
kseed: K,
vseed: V,
) -> Result<Option<((K::Value, V::Value), Option<Self>)>, Self::Error>where
K: DeserializeSeed<'de>,
V: DeserializeSeed<'de>,
This convenience method returns the Ok(Some(((key, value), access)))
for the next key-value pair in the map, or Ok(None) of there are no
remaining entries. The returned access object can be used to retrieve
the next entry in the map.
By default this calls next_key_seed followed by
next_value_seed; implementors
should override it if a more efficient implementation is possible.
The seed allows for passing data into a Deserialize implementation
at runtime; typically it makes more sense to call next_entry.
Sourcefn next_entry<K, V>(self) -> Result<Option<((K, V), Option<Self>)>, Self::Error>where
K: Deserialize<'de>,
V: Deserialize<'de>,
Self::Value: MapValueAccess<'de, Error = Self::Error>,
fn next_entry<K, V>(self) -> Result<Option<((K, V), Option<Self>)>, Self::Error>where
K: Deserialize<'de>,
V: Deserialize<'de>,
Self::Value: MapValueAccess<'de, Error = Self::Error>,
This convenience method returns the Ok(Some(((key, value), access)))
for the next key-value pair in the map, or Ok(None) of there are no
remaining entries. The returned access object can be used to retrieve
the next entry in the map.
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.