Skip to content

Commit

Permalink
Merge pull request #2305 from serde-rs/enumaccessdeserializer
Browse files Browse the repository at this point in the history
Add EnumAccessDeserializer to turn EnumAccess into a Deserializer
  • Loading branch information
dtolnay authored Oct 21, 2022
2 parents 3fd8e52 + 354b48f commit 6d00971
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions serde/src/de/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1510,6 +1510,41 @@ where

////////////////////////////////////////////////////////////////////////////////

/// A deserializer holding an `EnumAccess`.
#[derive(Clone, Debug)]
pub struct EnumAccessDeserializer<A> {
access: A,
}

impl<A> EnumAccessDeserializer<A> {
/// Construct a new `EnumAccessDeserializer<A>`.
pub fn new(access: A) -> Self {
EnumAccessDeserializer { access: access }
}
}

impl<'de, A> de::Deserializer<'de> for EnumAccessDeserializer<A>
where
A: de::EnumAccess<'de>,
{
type Error = A::Error;

fn deserialize_any<V>(self, visitor: V) -> Result<V::Value, Self::Error>
where
V: de::Visitor<'de>,
{
visitor.visit_enum(self.access)
}

forward_to_deserialize_any! {
bool i8 i16 i32 i64 i128 u8 u16 u32 u64 u128 f32 f64 char str string
bytes byte_buf option unit unit_struct newtype_struct seq tuple
tuple_struct map struct enum identifier ignored_any
}
}

////////////////////////////////////////////////////////////////////////////////

mod private {
use lib::*;

Expand Down

0 comments on commit 6d00971

Please sign in to comment.