Rename de::VariantVisitor::visit_{map,seq} to visit_{struct,tuple}

This commit is contained in:
Erick Tryzelaar 2015-07-29 12:24:16 -07:00
parent 7585ce9ed4
commit 351b7039a8
6 changed files with 36 additions and 32 deletions

View File

@ -916,11 +916,11 @@ impl<T, E> Deserialize for Result<T, E> where T: Deserialize, E: Deserialize {
{ {
match try!(visitor.visit_variant()) { match try!(visitor.visit_variant()) {
Field::Ok => { Field::Ok => {
let (value,) = try!(visitor.visit_seq(1, TupleVisitor1::new())); let (value,) = try!(visitor.visit_tuple(1, TupleVisitor1::new()));
Ok(Ok(value)) Ok(Ok(value))
} }
Field::Err => { Field::Err => {
let (value,) = try!(visitor.visit_seq(1, TupleVisitor1::new())); let (value,) = try!(visitor.visit_tuple(1, TupleVisitor1::new()));
Ok(Err(value)) Ok(Err(value))
} }
} }

View File

@ -584,17 +584,19 @@ pub trait VariantVisitor {
Err(Error::syntax_error()) Err(Error::syntax_error())
} }
/// `visit_seq` is called when deserializing a tuple-like variant. /// `visit_tuple` is called when deserializing a tuple-like variant.
fn visit_seq<V>(&mut self, _len: usize, _visitor: V) -> Result<V::Value, Self::Error> fn visit_tuple<V>(&mut self,
_len: usize,
_visitor: V) -> Result<V::Value, Self::Error>
where V: Visitor where V: Visitor
{ {
Err(Error::syntax_error()) Err(Error::syntax_error())
} }
/// `visit_map` is called when deserializing a struct-like variant. /// `visit_struct` is called when deserializing a struct-like variant.
fn visit_map<V>(&mut self, fn visit_struct<V>(&mut self,
_fields: &'static [&'static str], _fields: &'static [&'static str],
_visitor: V) -> Result<V::Value, Self::Error> _visitor: V) -> Result<V::Value, Self::Error>
where V: Visitor where V: Visitor
{ {
Err(Error::syntax_error()) Err(Error::syntax_error())
@ -618,18 +620,20 @@ impl<'a, T> VariantVisitor for &'a mut T where T: VariantVisitor {
(**self).visit_simple() (**self).visit_simple()
} }
fn visit_seq<V>(&mut self, len: usize, visitor: V) -> Result<V::Value, T::Error> fn visit_tuple<V>(&mut self,
len: usize,
visitor: V) -> Result<V::Value, T::Error>
where V: Visitor, where V: Visitor,
{ {
(**self).visit_seq(len, visitor) (**self).visit_tuple(len, visitor)
} }
fn visit_map<V>(&mut self, fn visit_struct<V>(&mut self,
fields: &'static [&'static str], fields: &'static [&'static str],
visitor: V) -> Result<V::Value, T::Error> visitor: V) -> Result<V::Value, T::Error>
where V: Visitor, where V: Visitor,
{ {
(**self).visit_map(fields, visitor) (**self).visit_struct(fields, visitor)
} }
} }

View File

@ -641,7 +641,7 @@ fn deserialize_tuple_variant(
} }
} }
visitor.visit_seq($fields, $visitor_expr) visitor.visit_tuple($fields, $visitor_expr)
}) })
} }
@ -708,7 +708,7 @@ fn deserialize_struct_variant(
$fields_stmt $fields_stmt
visitor.visit_map(FIELDS, $visitor_expr) visitor.visit_struct(FIELDS, $visitor_expr)
}) })
} }

View File

@ -648,17 +648,17 @@ impl<Iter> de::VariantVisitor for Deserializer<Iter>
de::Deserialize::deserialize(self) de::Deserialize::deserialize(self)
} }
fn visit_seq<V>(&mut self, fn visit_tuple<V>(&mut self,
_len: usize, _len: usize,
visitor: V) -> Result<V::Value, Error> visitor: V) -> Result<V::Value, Error>
where V: de::Visitor, where V: de::Visitor,
{ {
de::Deserializer::visit(self, visitor) de::Deserializer::visit(self, visitor)
} }
fn visit_map<V>(&mut self, fn visit_struct<V>(&mut self,
_fields: &'static [&'static str], _fields: &'static [&'static str],
visitor: V) -> Result<V::Value, Error> visitor: V) -> Result<V::Value, Error>
where V: de::Visitor, where V: de::Visitor,
{ {
de::Deserializer::visit(self, visitor) de::Deserializer::visit(self, visitor)

View File

@ -753,9 +753,9 @@ impl<'a> de::VariantVisitor for VariantDeserializer<'a> {
de::Deserialize::deserialize(&mut Deserializer::new(self.val.take().unwrap())) de::Deserialize::deserialize(&mut Deserializer::new(self.val.take().unwrap()))
} }
fn visit_seq<V>(&mut self, fn visit_tuple<V>(&mut self,
_len: usize, _len: usize,
visitor: V) -> Result<V::Value, Error> visitor: V) -> Result<V::Value, Error>
where V: de::Visitor, where V: de::Visitor,
{ {
if let Value::Array(fields) = self.val.take().unwrap() { if let Value::Array(fields) = self.val.take().unwrap() {
@ -772,9 +772,9 @@ impl<'a> de::VariantVisitor for VariantDeserializer<'a> {
} }
} }
fn visit_map<V>(&mut self, fn visit_struct<V>(&mut self,
_fields: &'static[&'static str], _fields: &'static[&'static str],
visitor: V) -> Result<V::Value, Error> visitor: V) -> Result<V::Value, Error>
where V: de::Visitor, where V: de::Visitor,
{ {
if let Value::Object(fields) = self.val.take().unwrap() { if let Value::Object(fields) = self.val.take().unwrap() {

View File

@ -327,17 +327,17 @@ impl<'a> de::VariantVisitor for TokenDeserializerVariantVisitor<'a> {
de::Deserialize::deserialize(self.de) de::Deserialize::deserialize(self.de)
} }
fn visit_seq<V>(&mut self, fn visit_tuple<V>(&mut self,
_len: usize, _len: usize,
visitor: V) -> Result<V::Value, Error> visitor: V) -> Result<V::Value, Error>
where V: de::Visitor, where V: de::Visitor,
{ {
de::Deserializer::visit(self.de, visitor) de::Deserializer::visit(self.de, visitor)
} }
fn visit_map<V>(&mut self, fn visit_struct<V>(&mut self,
_fields: &'static [&'static str], _fields: &'static [&'static str],
visitor: V) -> Result<V::Value, Error> visitor: V) -> Result<V::Value, Error>
where V: de::Visitor, where V: de::Visitor,
{ {
de::Deserializer::visit(self.de, visitor) de::Deserializer::visit(self.de, visitor)