Trait serde::de::VariantVisitor [] [src]

pub trait VariantVisitor: Sized {
    type Error: Error;
    fn visit_unit(self) -> Result<(), Self::Error>;
    fn visit_newtype_seed<T>(self, seed: T) -> Result<T::Value, Self::Error> where T: DeserializeSeed;
    fn visit_tuple<V>(self,
                      len: usize,
                      visitor: V)
                      -> Result<V::Value, Self::Error> where V: Visitor; fn visit_struct<V>(self,
                       fields: &'static [&'static str],
                       visitor: V)
                       -> Result<V::Value, Self::Error> where V: Visitor; fn visit_newtype<T>(self) -> Result<T, Self::Error> where T: Deserialize { ... } }

VariantVisitor is a visitor that is created by the Deserializer and passed to the Deserialize to deserialize the content of a particular enum variant.

Associated Types

The error type that can be returned if some error occurs during deserialization. Must match the error type of our EnumVisitor.

Required Methods

Called when deserializing a variant with no values.

If the data contains a different type of variant, the following invalid_type error should be constructed:

fn visit_unit(self) -> Result<(), Self::Error> {
    // What the data actually contained; suppose it is a tuple variant.
    let unexp = Unexpected::TupleVariant;
    Err(de::Error::invalid_type(unexp, &"unit variant"))
}

Called when deserializing a variant with a single value.

Deserialize implementations should typically use VariantVisitor::visit_newtype instead.

If the data contains a different type of variant, the following invalid_type error should be constructed:

fn visit_newtype_seed<T>(self, _seed: T) -> Result<T::Value, Self::Error>
    where T: de::DeserializeSeed
{
    // What the data actually contained; suppose it is a unit variant.
    let unexp = Unexpected::UnitVariant;
    Err(de::Error::invalid_type(unexp, &"newtype variant"))
}

Called when deserializing a tuple-like variant.

The len is the number of fields expected in the tuple variant.

If the data contains a different type of variant, the following invalid_type error should be constructed:

fn visit_tuple<V>(self,
                  _len: usize,
                  _visitor: V) -> Result<V::Value, Self::Error>
    where V: Visitor
{
    // What the data actually contained; suppose it is a unit variant.
    let unexp = Unexpected::UnitVariant;
    Err(Error::invalid_type(unexp, &"tuple variant"))
}

Called when deserializing a struct-like variant.

The fields are the names of the fields of the struct variant.

If the data contains a different type of variant, the following invalid_type error should be constructed:

fn visit_struct<V>(self,
                   _fields: &'static [&'static str],
                   _visitor: V) -> Result<V::Value, Self::Error>
    where V: Visitor
{
    // What the data actually contained; suppose it is a unit variant.
    let unexp = Unexpected::UnitVariant;
    Err(Error::invalid_type(unexp, &"struct variant"))
}

Provided Methods

Called when deserializing a variant with a single value.

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

Implementors