From 4722571a4deffd51bd40619ef74008a1b493f916 Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Wed, 20 Jul 2016 10:33:28 +0200 Subject: [PATCH] make `VariantVisitor` pure --- serde/src/de/mod.rs | 16 +++------------ serde/src/de/value.rs | 46 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 13 deletions(-) diff --git a/serde/src/de/mod.rs b/serde/src/de/mod.rs index 8c3e28fe..4c3e0cbd 100644 --- a/serde/src/de/mod.rs +++ b/serde/src/de/mod.rs @@ -846,29 +846,19 @@ pub trait VariantVisitor { /// uses the `visit_tuple` method to deserialize the value. #[inline] fn visit_newtype(&mut self) -> Result - where T: Deserialize, - { - let (value,) = try!(self.visit_tuple(1, impls::TupleVisitor1::new())); - Ok(value) - } + where T: Deserialize; /// `visit_tuple` is called when deserializing a tuple-like variant. fn visit_tuple(&mut self, _len: usize, _visitor: V) -> Result - where V: Visitor - { - Err(Error::invalid_type(Type::TupleVariant)) - } + where V: Visitor; /// `visit_struct` is called when deserializing a struct-like variant. fn visit_struct(&mut self, _fields: &'static [&'static str], _visitor: V) -> Result - where V: Visitor - { - Err(Error::invalid_type(Type::StructVariant)) - } + where V: Visitor; } impl<'a, T> VariantVisitor for &'a mut T where T: VariantVisitor { diff --git a/serde/src/de/value.rs b/serde/src/de/value.rs index be65e231..1428ff22 100644 --- a/serde/src/de/value.rs +++ b/serde/src/de/value.rs @@ -338,6 +338,29 @@ impl<'a, E> de::VariantVisitor for StrDeserializer<'a, E> fn visit_unit(&mut self) -> Result<(), Self::Error> { Ok(()) } + + fn visit_newtype(&mut self) -> Result + where T: super::Deserialize, + { + let (value,) = try!(self.visit_tuple(1, super::impls::TupleVisitor1::new())); + Ok(value) + } + + fn visit_tuple(&mut self, + _len: usize, + _visitor: V) -> Result + where V: super::Visitor + { + Err(super::Error::invalid_type(super::Type::TupleVariant)) + } + + fn visit_struct(&mut self, + _fields: &'static [&'static str], + _visitor: V) -> Result + where V: super::Visitor + { + Err(super::Error::invalid_type(super::Type::StructVariant)) + } } /////////////////////////////////////////////////////////////////////////////// @@ -413,6 +436,29 @@ impl<'a, E> de::VariantVisitor for StringDeserializer fn visit_unit(&mut self) -> Result<(), Self::Error> { Ok(()) } + + fn visit_newtype(&mut self) -> Result + where T: super::Deserialize, + { + let (value,) = try!(self.visit_tuple(1, super::impls::TupleVisitor1::new())); + Ok(value) + } + + fn visit_tuple(&mut self, + _len: usize, + _visitor: V) -> Result + where V: super::Visitor + { + Err(super::Error::invalid_type(super::Type::TupleVariant)) + } + + fn visit_struct(&mut self, + _fields: &'static [&'static str], + _visitor: V) -> Result + where V: super::Visitor + { + Err(super::Error::invalid_type(super::Type::StructVariant)) + } } ///////////////////////////////////////////////////////////////////////////////