pub trait EnumAccess<'de>: Sized {
type Error: Error;
type Variant: VariantAccess<'de, Error = Self::Error>;
// Required method
fn variant_seed<V>(
self,
seed: V,
) -> Result<(V::Value, Self::Variant), Self::Error>
where V: DeserializeSeed<'de>;
// Provided method
fn variant<V>(self) -> Result<(V, Self::Variant), Self::Error>
where V: Deserialize<'de> { ... }
}
Expand description
Provides a Visitor
access to the data of an enum in the input.
EnumAccess
is created by the Deserializer
and passed to the
Visitor
in order to identify which variant of an enum to deserialize.
§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 EnumAccess
for a basic JSON data format.
Required Associated Types§
Sourcetype Error: Error
type Error: Error
The error type that can be returned if some error occurs during deserialization.
Sourcetype Variant: VariantAccess<'de, Error = Self::Error>
type Variant: VariantAccess<'de, Error = Self::Error>
The Visitor
that will be used to deserialize the content of the enum
variant.
Required Methods§
Sourcefn variant_seed<V>(
self,
seed: V,
) -> Result<(V::Value, Self::Variant), Self::Error>where
V: DeserializeSeed<'de>,
fn variant_seed<V>(
self,
seed: V,
) -> Result<(V::Value, Self::Variant), Self::Error>where
V: DeserializeSeed<'de>,
variant
is called to identify which variant to deserialize.
Deserialize
implementations should typically use EnumAccess::variant
instead.
Provided Methods§
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.