Use forward_deserializer macro for define StrDeserializer for IdentifierDeserializer
This commit is contained in:
parent
094f63b86a
commit
9e1f573f88
@ -116,6 +116,7 @@ use lib::*;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#[macro_use]
|
||||
pub mod value;
|
||||
|
||||
mod from_primitive;
|
||||
|
@ -32,6 +32,8 @@ use ser;
|
||||
|
||||
/// For structs that contain a PhantomData. We do not want the trait
|
||||
/// bound `E: Clone` inferred by derive(Clone).
|
||||
#[doc(hidden)]
|
||||
#[macro_export]
|
||||
macro_rules! impl_copy_clone {
|
||||
($ty:ident $(<$lifetime:tt>)*) => {
|
||||
impl<$($lifetime,)* E> Copy for $ty<$($lifetime,)* E> {}
|
||||
@ -45,6 +47,8 @@ macro_rules! impl_copy_clone {
|
||||
}
|
||||
|
||||
/// Creates a deserializer any method of which forwards to the specified visitor method
|
||||
#[doc(hidden)]
|
||||
#[macro_export(local_inner_macros)]
|
||||
macro_rules! forward_deserializer {
|
||||
// Non-borrowed references
|
||||
(
|
||||
@ -72,15 +76,15 @@ macro_rules! forward_deserializer {
|
||||
|
||||
impl_copy_clone!($deserializer $(<$lifetime>)*);
|
||||
|
||||
impl<'de, $($lifetime,)* E> de::Deserializer<'de> for $deserializer<$($lifetime,)* E>
|
||||
impl<'de, $($lifetime,)* E> $crate::de::Deserializer<'de> for $deserializer<$($lifetime,)* E>
|
||||
where
|
||||
E: de::Error,
|
||||
E: $crate::de::Error,
|
||||
{
|
||||
type Error = E;
|
||||
|
||||
fn deserialize_any<V>(self, visitor: V) -> Result<V::Value, Self::Error>
|
||||
fn deserialize_any<V>(self, visitor: V) -> $crate::export::Result<V::Value, Self::Error>
|
||||
where
|
||||
V: de::Visitor<'de>,
|
||||
V: $crate::de::Visitor<'de>,
|
||||
{
|
||||
visitor.$visit(self.value)
|
||||
}
|
||||
@ -116,15 +120,15 @@ macro_rules! forward_deserializer {
|
||||
|
||||
impl_copy_clone!($deserializer<'de>);
|
||||
|
||||
impl<'de, E> de::Deserializer<'de> for $deserializer<'de, E>
|
||||
impl<'de, E> $crate::de::Deserializer<'de> for $deserializer<'de, E>
|
||||
where
|
||||
E: de::Error,
|
||||
E: $crate::de::Error,
|
||||
{
|
||||
type Error = E;
|
||||
|
||||
fn deserialize_any<V>(self, visitor: V) -> Result<V::Value, Self::Error>
|
||||
fn deserialize_any<V>(self, visitor: V) -> $crate::export::Result<V::Value, Self::Error>
|
||||
where
|
||||
V: de::Visitor<'de>,
|
||||
V: $crate::de::Visitor<'de>,
|
||||
{
|
||||
visitor.$visit(self.value)
|
||||
}
|
||||
|
@ -256,6 +256,7 @@ mod macros;
|
||||
#[macro_use]
|
||||
mod integer128;
|
||||
|
||||
#[macro_use]
|
||||
pub mod de;
|
||||
pub mod ser;
|
||||
|
||||
|
@ -2554,10 +2554,7 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
pub struct StrDeserializer<'a, E> {
|
||||
value: &'a str,
|
||||
marker: PhantomData<E>,
|
||||
}
|
||||
forward_deserializer!(ref StrDeserializer<'a>(&'a str) => visit_str);
|
||||
|
||||
impl<'a, E> IdentifierDeserializer<'a, E> for &'a str
|
||||
where
|
||||
@ -2566,30 +2563,7 @@ where
|
||||
type Deserializer = StrDeserializer<'a, E>;
|
||||
|
||||
fn from(self) -> Self::Deserializer {
|
||||
StrDeserializer {
|
||||
value: self,
|
||||
marker: PhantomData,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'de, 'a, E> Deserializer<'de> for StrDeserializer<'a, E>
|
||||
where
|
||||
E: Error,
|
||||
{
|
||||
type Error = E;
|
||||
|
||||
fn deserialize_any<V>(self, visitor: V) -> Result<V::Value, Self::Error>
|
||||
where
|
||||
V: Visitor<'de>,
|
||||
{
|
||||
visitor.visit_str(self.value)
|
||||
}
|
||||
|
||||
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
|
||||
StrDeserializer::new(self)
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user