Trait serde::de::SeqAccess

source ·
pub trait SeqAccess<'de> {
    type Error: Error;

    // Required method
    fn next_element_seed<T>(
        &mut self,
        seed: T,
    ) -> Result<Option<T::Value>, Self::Error>
       where T: DeserializeSeed<'de>;

    // Provided methods
    fn next_element<T>(&mut self) -> Result<Option<T>, Self::Error>
       where T: Deserialize<'de> { ... }
    fn size_hint(&self) -> Option<usize> { ... }
}
Expand description

Provides a Visitor access to each element of a sequence in the input.

This is a trait that a Deserializer passes to a Visitor implementation, which deserializes each item in a sequence.

§Lifetime

The 'de lifetime of this trait is the lifetime of data that may be borrowed by deserialized sequence elements. 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 SeqAccess 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_element_seed<T>( &mut self, seed: T, ) -> Result<Option<T::Value>, Self::Error>
where T: DeserializeSeed<'de>,

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

Deserialize implementations should typically use SeqAccess::next_element instead.

Provided Methods§

source

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

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

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

source

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

Returns the number of elements remaining in the sequence, if known.

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

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

source§

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

source§

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

source§

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

source§

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

Implementors§

source§

impl<'de, A, B, E> SeqAccess<'de> for PairVisitor<A, B, E>
where A: IntoDeserializer<'de, E>, B: IntoDeserializer<'de, E>, E: Error,

source§

type Error = E

source§

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

source§

type Error = E

source§

impl<'de, I, T, E> SeqAccess<'de> for SeqDeserializer<I, E>
where I: Iterator<Item = T>, T: IntoDeserializer<'de, E>, E: Error,

source§

type Error = E