Rename ser::Serializer::visit_enum_{unit,seq,map} to visit_{unit,tuple,struct}_variant

This commit is contained in:
Erick Tryzelaar 2015-07-29 12:25:16 -07:00
parent 351b7039a8
commit d2fef27721
6 changed files with 68 additions and 64 deletions

View File

@ -631,7 +631,7 @@ impl<T, E> Serialize for Result<T, E> where T: Serialize, E: Serialize {
}
}
serializer.visit_enum_seq("Result", 0, "Ok", Visitor(Some(value)))
serializer.visit_tuple_variant("Result", 0, "Ok", Visitor(Some(value)))
}
Result::Err(ref value) => {
struct Visitor<'a, E: 'a>(Option<&'a E>);
@ -652,7 +652,7 @@ impl<T, E> Serialize for Result<T, E> where T: Serialize, E: Serialize {
}
}
serializer.visit_enum_seq("Result", 1, "Err", Visitor(Some(value)))
serializer.visit_tuple_variant("Result", 1, "Err", Visitor(Some(value)))
}
}
}

View File

@ -118,10 +118,10 @@ pub trait Serializer {
}
#[inline]
fn visit_enum_unit(&mut self,
_name: &'static str,
_variant_index: usize,
_variant: &'static str) -> Result<(), Self::Error> {
fn visit_unit_variant(&mut self,
_name: &'static str,
_variant_index: usize,
_variant: &'static str) -> Result<(), Self::Error> {
self.visit_unit()
}
@ -175,18 +175,18 @@ pub trait Serializer {
}
#[inline]
fn visit_enum_seq<V>(&mut self,
_name: &'static str,
_variant_index: usize,
variant: &'static str,
visitor: V) -> Result<(), Self::Error>
fn visit_tuple_variant<V>(&mut self,
_name: &'static str,
_variant_index: usize,
variant: &'static str,
visitor: V) -> Result<(), Self::Error>
where V: SeqVisitor,
{
self.visit_tuple_struct(variant, visitor)
}
#[inline]
fn visit_enum_seq_elt<T>(&mut self, value: T) -> Result<(), Self::Error>
fn visit_tuple_variant_elt<T>(&mut self, value: T) -> Result<(), Self::Error>
where T: Serialize
{
self.visit_tuple_struct_elt(value)
@ -209,7 +209,9 @@ pub trait Serializer {
}
#[inline]
fn visit_struct_elt<K, V>(&mut self, key: K, value: V) -> Result<(), Self::Error>
fn visit_struct_elt<K, V>(&mut self,
key: K,
value: V) -> Result<(), Self::Error>
where K: Serialize,
V: Serialize,
{
@ -217,18 +219,20 @@ pub trait Serializer {
}
#[inline]
fn visit_enum_map<V>(&mut self,
_name: &'static str,
_variant_index: usize,
variant: &'static str,
visitor: V) -> Result<(), Self::Error>
fn visit_struct_variant<V>(&mut self,
_name: &'static str,
_variant_index: usize,
variant: &'static str,
visitor: V) -> Result<(), Self::Error>
where V: MapVisitor,
{
self.visit_struct(variant, visitor)
}
#[inline]
fn visit_enum_map_elt<K, V>(&mut self, key: K, value: V) -> Result<(), Self::Error>
fn visit_struct_variant_elt<K, V>(&mut self,
key: K,
value: V) -> Result<(), Self::Error>
where K: Serialize,
V: Serialize,
{

View File

@ -288,7 +288,7 @@ fn serialize_variant(
quote_arm!(cx,
$pat => {
::serde::ser::Serializer::visit_enum_unit(
::serde::ser::Serializer::visit_unit_variant(
serializer,
$type_name,
$variant_index,
@ -421,7 +421,7 @@ fn serialize_tuple_variant(
quote_expr!(cx, {
$visitor_struct
$visitor_impl
serializer.visit_enum_seq($type_name, $variant_index, $variant_name, Visitor {
serializer.visit_tuple_variant($type_name, $variant_index, $variant_name, Visitor {
value: $value_expr,
state: 0,
_structure_ty: ::std::marker::PhantomData::<&$structure_ty>,
@ -476,7 +476,7 @@ fn serialize_struct_variant(
quote_expr!(cx, {
$visitor_struct
$visitor_impl
serializer.visit_enum_map($type_name, $variant_index, $variant_name, Visitor {
serializer.visit_struct_variant($type_name, $variant_index, $variant_name, Visitor {
value: $value_expr,
state: 0,
_structure_ty: ::std::marker::PhantomData::<&$structure_ty>,

View File

@ -159,10 +159,10 @@ impl<W, F> ser::Serializer for Serializer<W, F>
}
#[inline]
fn visit_enum_unit(&mut self,
_name: &str,
_variant_index: usize,
variant: &str) -> io::Result<()> {
fn visit_unit_variant(&mut self,
_name: &str,
_variant_index: usize,
variant: &str) -> io::Result<()> {
try!(self.formatter.open(&mut self.writer, b'{'));
try!(self.formatter.comma(&mut self.writer, true));
try!(self.visit_str(variant));
@ -209,11 +209,11 @@ impl<W, F> ser::Serializer for Serializer<W, F>
}
#[inline]
fn visit_enum_seq<V>(&mut self,
_name: &str,
_variant_index: usize,
variant: &str,
visitor: V) -> io::Result<()>
fn visit_tuple_variant<V>(&mut self,
_name: &str,
_variant_index: usize,
variant: &str,
visitor: V) -> io::Result<()>
where V: ser::SeqVisitor,
{
try!(self.formatter.open(&mut self.writer, b'{'));
@ -257,11 +257,11 @@ impl<W, F> ser::Serializer for Serializer<W, F>
}
#[inline]
fn visit_enum_map<V>(&mut self,
_name: &str,
_variant_index: usize,
variant: &str,
visitor: V) -> io::Result<()>
fn visit_struct_variant<V>(&mut self,
_name: &str,
_variant_index: usize,
variant: &str,
visitor: V) -> io::Result<()>
where V: ser::MapVisitor,
{
try!(self.formatter.open(&mut self.writer, b'{'));

View File

@ -459,10 +459,10 @@ impl ser::Serializer for Serializer {
}
#[inline]
fn visit_enum_unit(&mut self,
_name: &str,
_variant_index: usize,
variant: &str) -> Result<(), ()> {
fn visit_unit_variant(&mut self,
_name: &str,
_variant_index: usize,
variant: &str) -> Result<(), ()> {
let mut values = BTreeMap::new();
values.insert(variant.to_string(), Value::Array(vec![]));
@ -509,11 +509,11 @@ impl ser::Serializer for Serializer {
}
#[inline]
fn visit_enum_seq<V>(&mut self,
_name: &str,
_variant_index: usize,
variant: &str,
visitor: V) -> Result<(), ()>
fn visit_tuple_variant<V>(&mut self,
_name: &str,
_variant_index: usize,
variant: &str,
visitor: V) -> Result<(), ()>
where V: ser::SeqVisitor,
{
try!(self.visit_seq(visitor));
@ -572,11 +572,11 @@ impl ser::Serializer for Serializer {
}
#[inline]
fn visit_enum_map<V>(&mut self,
_name: &str,
_variant_index: usize,
variant: &str,
visitor: V) -> Result<(), ()>
fn visit_struct_variant<V>(&mut self,
_name: &str,
_variant_index: usize,
variant: &str,
visitor: V) -> Result<(), ()>
where V: ser::MapVisitor,
{
try!(self.visit_map(visitor));

View File

@ -98,10 +98,10 @@ impl<'a> Serializer for AssertSerializer<'a> {
Ok(())
}
fn visit_enum_unit(&mut self,
name: &str,
_variant_index: usize,
variant: &str) -> Result<(), ()> {
fn visit_unit_variant(&mut self,
name: &str,
_variant_index: usize,
variant: &str) -> Result<(), ()> {
assert_eq!(
self.iter.next().unwrap(),
Token::EnumUnit(name, variant)
@ -221,11 +221,11 @@ impl<'a> Serializer for AssertSerializer<'a> {
self.visit_sequence(visitor)
}
fn visit_enum_seq<V>(&mut self,
name: &str,
_variant_index: usize,
variant: &str,
visitor: V) -> Result<(), ()>
fn visit_tuple_variant<V>(&mut self,
name: &str,
_variant_index: usize,
variant: &str,
visitor: V) -> Result<(), ()>
where V: SeqVisitor
{
let len = visitor.len();
@ -268,11 +268,11 @@ impl<'a> Serializer for AssertSerializer<'a> {
self.visit_mapping(visitor)
}
fn visit_enum_map<V>(&mut self,
name: &str,
_variant_index: usize,
variant: &str,
visitor: V) -> Result<(), ()>
fn visit_struct_variant<V>(&mut self,
name: &str,
_variant_index: usize,
variant: &str,
visitor: V) -> Result<(), ()>
where V: MapVisitor
{
let len = visitor.len();