Skip to content
This repository has been archived by the owner on Mar 25, 2024. It is now read-only.

Commit

Permalink
Merge pull request #339 from dtolnay/deserializertaggedvalue
Browse files Browse the repository at this point in the history
Implement Deserializer for TaggedValue and &TaggedValue
  • Loading branch information
dtolnay authored Oct 21, 2022
2 parents c5523fe + 371f764 commit 8d95125
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions src/value/tagged.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use serde::de::value::{BorrowedStrDeserializer, StrDeserializer};
use serde::de::{
Deserialize, DeserializeSeed, Deserializer, EnumAccess, Error as _, VariantAccess, Visitor,
};
use serde::forward_to_deserialize_any;
use serde::ser::{Serialize, SerializeMap, Serializer};
use std::cmp::Ordering;
use std::fmt::{self, Debug, Display};
Expand Down Expand Up @@ -213,6 +214,31 @@ impl<'de> Deserialize<'de> for TaggedValue {
}
}

impl<'de> Deserializer<'de> for TaggedValue {
type Error = Error;

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

fn deserialize_ignored_any<V>(self, visitor: V) -> Result<V::Value, Error>
where
V: Visitor<'de>,
{
drop(self);
visitor.visit_unit()
}

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

impl<'de> EnumAccess<'de> for TaggedValue {
type Error = Error;
type Variant = Value;
Expand Down Expand Up @@ -268,6 +294,30 @@ impl<'de> VariantAccess<'de> for Value {
}
}

impl<'de> Deserializer<'de> for &'de TaggedValue {
type Error = Error;

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

fn deserialize_ignored_any<V>(self, visitor: V) -> Result<V::Value, Error>
where
V: Visitor<'de>,
{
visitor.visit_unit()
}

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

impl<'de> EnumAccess<'de> for &'de TaggedValue {
type Error = Error;
type Variant = &'de Value;
Expand Down

0 comments on commit 8d95125

Please sign in to comment.