Trait VariantAccess

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

    // Required method
    fn unit_variant(self) -> Result<(), Self::Error>;
}
Expand description

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

§Lifetime

The 'de lifetime of this trait is the lifetime of data that may be borrowed by the deserialized enum variant. 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 VariantAccess 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. Must match the error type of our EnumAccess.

Required Methods§

Source

fn unit_variant(self) -> Result<(), Self::Error>

Called when deserializing a variant with no values.

Check that the value of the enum is of a valid type immediately after deserialization with EnumAccess::variant.

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.

Implementors§