1//! Deserializing `enum` or `bitflags`
2use super::XmlDeserializer;
3use crate::errors::de::{Error, Result};
4use havok_serde::de::{DeserializeSeed, EnumAccess, VariantAccess};
56/// A enum for deserializing each variant in an `enum`.
7///
8/// # Expected XML
9/// - Note that `</hkparam>` confirms the presence but does not consume.
10/// ```xml
11/// EVENT_MODE_IGNORE_FROM_GENERATOR</hkparam>
12/// ```
13#[derive(Debug)]
14pub struct EnumDeserializer<'a, 'de: 'a> {
15 de: &'a mut XmlDeserializer<'de>,
16}
1718impl<'a, 'de> EnumDeserializer<'a, 'de> {
19#[inline]
20pub const fn new(de: &'a mut XmlDeserializer<'de>) -> Self {
21 EnumDeserializer { de }
22 }
23}
2425// `EnumAccess` is provided to the `Visitor` to give it the ability to determine
26// which variant of the enum is supposed to be deserialized.
27//
28// Note that all enum deserialization methods in Serde refer exclusively to the
29// "externally tagged" enum representation.
30impl<'de> EnumAccess<'de> for EnumDeserializer<'_, 'de> {
31type Error = Error;
32type Variant = Self;
3334#[inline]
35fn variant_seed<V>(self, seed: V) -> Result<(V::Value, Self::Variant)>
36where
37V: DeserializeSeed<'de>,
38 {
39let val = seed.deserialize(&mut *self.de)?;
40Ok((val, self))
41 }
42}
4344/// `VariantAccess` is provided to the `Visitor` to give it the ability to see
45/// the content of the single variant that it decided to deserialize.
46impl<'de> VariantAccess<'de> for EnumDeserializer<'_, 'de> {
47type Error = Error;
4849#[inline]
50fn unit_variant(self) -> Result<(), Self::Error> {
51Ok(())
52 }
53}