From 6715fb665216514fdd214fd58d3fa2664d16c7a9 Mon Sep 17 00:00:00 2001 From: Erick Tryzelaar Date: Wed, 29 Jul 2015 15:41:37 -0700 Subject: [PATCH] Rename visit_simple to visit_newtype --- serde/src/de/impls.rs | 4 ++-- serde/src/de/mod.rs | 8 ++++---- serde_codegen/src/de.rs | 2 +- serde_json/src/de.rs | 4 +++- serde_json/src/value.rs | 2 +- serde_tests/tests/test_de.rs | 12 ++++++------ 6 files changed, 17 insertions(+), 15 deletions(-) diff --git a/serde/src/de/impls.rs b/serde/src/de/impls.rs index 0d1d8a4f..1c74c5e5 100644 --- a/serde/src/de/impls.rs +++ b/serde/src/de/impls.rs @@ -924,11 +924,11 @@ impl Deserialize for Result where T: Deserialize, E: Deserialize { { match try!(visitor.visit_variant()) { Field::Ok => { - let value = try!(visitor.visit_simple()); + let value = try!(visitor.visit_newtype()); Ok(Ok(value)) } Field::Err => { - let value = try!(visitor.visit_simple()); + let value = try!(visitor.visit_newtype()); Ok(Err(value)) } } diff --git a/serde/src/de/mod.rs b/serde/src/de/mod.rs index 0f865920..e00140b0 100644 --- a/serde/src/de/mod.rs +++ b/serde/src/de/mod.rs @@ -579,8 +579,8 @@ pub trait VariantVisitor { Err(Error::syntax_error()) } - /// `visit_simple` is called when deserializing a variant with a single value. - fn visit_simple(&mut self) -> Result + /// `visit_newtype` is called when deserializing a variant with a single value. + fn visit_newtype(&mut self) -> Result where T: Deserialize, { Err(Error::syntax_error()) @@ -618,10 +618,10 @@ impl<'a, T> VariantVisitor for &'a mut T where T: VariantVisitor { (**self).visit_unit() } - fn visit_simple(&mut self) -> Result + fn visit_newtype(&mut self) -> Result where D: Deserialize, { - (**self).visit_simple() + (**self).visit_newtype() } fn visit_tuple(&mut self, diff --git a/serde_codegen/src/de.rs b/serde_codegen/src/de.rs index a9807060..59ca5a57 100644 --- a/serde_codegen/src/de.rs +++ b/serde_codegen/src/de.rs @@ -574,7 +574,7 @@ fn deserialize_variant( } ast::TupleVariantKind(ref args) if args.len() == 1 => { quote_expr!(cx, { - let val = try!(visitor.visit_simple()); + let val = try!(visitor.visit_newtype()); Ok($type_ident::$variant_ident(val)) }) } diff --git a/serde_json/src/de.rs b/serde_json/src/de.rs index 5fbbfb1c..3c286ae7 100644 --- a/serde_json/src/de.rs +++ b/serde_json/src/de.rs @@ -644,7 +644,9 @@ impl de::VariantVisitor for Deserializer de::Deserialize::deserialize(self) } - fn visit_simple(&mut self) -> Result { + fn visit_newtype(&mut self) -> Result + where T: de::Deserialize, + { de::Deserialize::deserialize(self) } diff --git a/serde_json/src/value.rs b/serde_json/src/value.rs index 53bdf017..d395298e 100644 --- a/serde_json/src/value.rs +++ b/serde_json/src/value.rs @@ -747,7 +747,7 @@ impl<'a> de::VariantVisitor for VariantDeserializer<'a> { de::Deserialize::deserialize(&mut Deserializer::new(self.val.take().unwrap())) } - fn visit_simple(&mut self) -> Result + fn visit_newtype(&mut self) -> Result where T: de::Deserialize, { de::Deserialize::deserialize(&mut Deserializer::new(self.val.take().unwrap())) diff --git a/serde_tests/tests/test_de.rs b/serde_tests/tests/test_de.rs index 2783654c..6f45a0af 100644 --- a/serde_tests/tests/test_de.rs +++ b/serde_tests/tests/test_de.rs @@ -40,7 +40,7 @@ enum Token { EnumStart(&'static str), EnumUnit, - EnumSimple, + EnumNewtype, EnumSeq, EnumMap, EnumEnd, @@ -339,11 +339,11 @@ impl<'a> de::VariantVisitor for TokenDeserializerVariantVisitor<'a> { } } - fn visit_simple(&mut self) -> Result + fn visit_newtype(&mut self) -> Result where T: de::Deserialize, { match self.de.tokens.next() { - Some(Token::EnumSimple) => { + Some(Token::EnumNewtype) => { de::Deserialize::deserialize(self.de) } Some(_) => Err(Error::SyntaxError), @@ -541,7 +541,7 @@ declare_tests! { Token::EnumStart("Result"), Token::Str("Ok"), - Token::EnumSimple, + Token::EnumNewtype, Token::I32(0), Token::SeqEnd, ], @@ -549,7 +549,7 @@ declare_tests! { Token::EnumStart("Result"), Token::Str("Err"), - Token::EnumSimple, + Token::EnumNewtype, Token::I32(1), Token::SeqEnd, ], @@ -934,7 +934,7 @@ declare_tests! { Token::EnumStart("Enum"), Token::Str("Simple"), - Token::EnumSimple, + Token::EnumNewtype, Token::I32(1), Token::EnumEnd, ],