Rename named_* to use {enum,struct,unit}_*

This better reflects how they're used.
This commit is contained in:
Erick Tryzelaar 2015-07-04 12:11:20 -07:00
parent d30cf07254
commit 10f23dddfe
8 changed files with 66 additions and 66 deletions

View File

@ -187,7 +187,7 @@ impl serde::Serialize for Point {
fn serialize<S>(&self, serializer: &mut S) -> Result<(), S::Error>
where S: serde::Serializer
{
serializer.visit_named_map("Point", PointMapVisitor {
serializer.visit_struct("Point", PointMapVisitor {
value: self,
state: 0,
})
@ -383,7 +383,7 @@ impl serde::Deserialize for Point {
fn deserialize<D>(deserializer: &mut D) -> Result<Point, D::Error>
where D: serde::de::Deserializer
{
deserializer.visit_named_map("Point", PointVisitor)
deserializer.visit_struct("Point", PointVisitor)
}
}

View File

@ -211,25 +211,25 @@ pub trait Deserializer {
/// This method hints that the `Deserialize` type is expecting a named unit. This allows
/// deserializers to a named unit that aren't tagged as a named unit.
#[inline]
fn visit_named_unit<V>(&mut self, _name: &str, visitor: V) -> Result<V::Value, Self::Error>
fn visit_unit_struct<V>(&mut self, _name: &str, visitor: V) -> Result<V::Value, Self::Error>
where V: Visitor,
{
self.visit(visitor)
}
/// This method hints that the `Deserialize` type is expecting a named sequence.
/// This allows deserializers to parse sequences that aren't tagged as sequences.
/// This method hints that the `Deserialize` type is expecting a tuple struct. This allows
/// deserializers to parse sequences that aren't tagged as sequences.
#[inline]
fn visit_named_seq<V>(&mut self, _name: &str, visitor: V) -> Result<V::Value, Self::Error>
fn visit_tuple_struct<V>(&mut self, _name: &str, visitor: V) -> Result<V::Value, Self::Error>
where V: Visitor,
{
self.visit_seq(visitor)
}
/// This method hints that the `Deserialize` type is expecting a named map. This allows
/// This method hints that the `Deserialize` type is expecting a struct. This allows
/// deserializers to parse sequences that aren't tagged as maps.
#[inline]
fn visit_named_map<V>(&mut self, _name: &str, visitor: V) -> Result<V::Value, Self::Error>
fn visit_struct<V>(&mut self, _name: &str, visitor: V) -> Result<V::Value, Self::Error>
where V: Visitor,
{
self.visit_map(visitor)
@ -386,7 +386,7 @@ pub trait Visitor {
}
#[inline]
fn visit_named_unit<E>(&mut self, _name: &str) -> Result<Self::Value, E>
fn visit_unit_struct<E>(&mut self, _name: &str) -> Result<Self::Value, E>
where E: Error,
{
self.visit_unit()

View File

@ -113,7 +113,7 @@ pub trait Serializer {
fn visit_unit(&mut self) -> Result<(), Self::Error>;
#[inline]
fn visit_named_unit(&mut self, _name: &str) -> Result<(), Self::Error> {
fn visit_unit_struct(&mut self, _name: &str) -> Result<(), Self::Error> {
self.visit_unit()
}
@ -150,7 +150,7 @@ pub trait Serializer {
}
#[inline]
fn visit_named_seq<V>(&mut self,
fn visit_tuple_struct<V>(&mut self,
_name: &'static str,
visitor: V) -> Result<(), Self::Error>
where V: SeqVisitor,
@ -159,7 +159,7 @@ pub trait Serializer {
}
#[inline]
fn visit_named_seq_elt<T>(&mut self, value: T) -> Result<(), Self::Error>
fn visit_tuple_struct_elt<T>(&mut self, value: T) -> Result<(), Self::Error>
where T: Serialize
{
self.visit_tuple_elt(value)
@ -172,14 +172,14 @@ pub trait Serializer {
visitor: V) -> Result<(), Self::Error>
where V: SeqVisitor,
{
self.visit_named_seq(variant, visitor)
self.visit_tuple_struct(variant, visitor)
}
#[inline]
fn visit_enum_seq_elt<T>(&mut self, value: T) -> Result<(), Self::Error>
where T: Serialize
{
self.visit_named_seq_elt(value)
self.visit_tuple_struct_elt(value)
}
fn visit_map<V>(&mut self, visitor: V) -> Result<(), Self::Error>
@ -190,7 +190,7 @@ pub trait Serializer {
V: Serialize;
#[inline]
fn visit_named_map<V>(&mut self,
fn visit_struct<V>(&mut self,
_name: &'static str,
visitor: V) -> Result<(), Self::Error>
where V: MapVisitor,
@ -199,7 +199,7 @@ pub trait Serializer {
}
#[inline]
fn visit_named_map_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,
{
@ -213,7 +213,7 @@ pub trait Serializer {
visitor: V) -> Result<(), Self::Error>
where V: MapVisitor,
{
self.visit_named_map(variant, visitor)
self.visit_struct(variant, visitor)
}
#[inline]
@ -221,7 +221,7 @@ pub trait Serializer {
where K: Serialize,
V: Serialize,
{
self.visit_named_map_elt(key, value)
self.visit_struct_elt(key, value)
}
/// Specify a format string for the serializer.

View File

@ -260,7 +260,7 @@ fn deserialize_unit_struct(
}
}
deserializer.visit_named_unit($type_name, __Visitor)
deserializer.visit_unit_struct($type_name, __Visitor)
})
}
@ -304,7 +304,7 @@ fn deserialize_tuple_struct(
}
}
deserializer.visit_named_seq($type_name, $visitor_expr)
deserializer.visit_tuple_struct($type_name, $visitor_expr)
})
}
@ -385,7 +385,7 @@ fn deserialize_struct(
}
}
deserializer.visit_named_map($type_name, $visitor_expr)
deserializer.visit_struct($type_name, $visitor_expr)
})
}

View File

@ -169,7 +169,7 @@ fn serialize_unit_struct(
) -> P<ast::Expr> {
let type_name = builder.expr().str(type_ident);
quote_expr!(cx, serializer.visit_named_unit($type_name))
quote_expr!(cx, serializer.visit_unit_struct($type_name))
}
fn serialize_tuple_struct(
@ -194,7 +194,7 @@ fn serialize_tuple_struct(
quote_expr!(cx, {
$visitor_struct
$visitor_impl
serializer.visit_named_seq($type_name, Visitor {
serializer.visit_tuple_struct($type_name, Visitor {
value: self,
state: 0,
_structure_ty: ::std::marker::PhantomData,
@ -226,7 +226,7 @@ fn serialize_struct(
quote_expr!(cx, {
$visitor_struct
$visitor_impl
serializer.visit_named_map($type_name, Visitor {
serializer.visit_struct($type_name, Visitor {
value: self,
state: 0,
_structure_ty: ::std::marker::PhantomData,
@ -476,7 +476,7 @@ fn serialize_tuple_struct_visitor(
quote_arm!(cx,
$i => {
self.state += 1;
let v = try!(serializer.visit_named_seq_elt(&$expr));
let v = try!(serializer.visit_tuple_struct_elt(&$expr));
Ok(Some(v))
}
)
@ -559,7 +559,7 @@ fn serialize_struct_visitor<I>(
Ok(
Some(
try!(
serializer.visit_named_map_elt(
serializer.visit_struct_elt(
$key_expr,
$value_expr,
)

View File

@ -398,7 +398,7 @@ mod deserializer {
}
}
fn visit_named_map<V>(&mut self, name: &str, mut visitor: V) -> Result<V::Value, Error>
fn visit_struct<V>(&mut self, name: &str, mut visitor: V) -> Result<V::Value, Error>
where V: de::Visitor,
{
match self.stack.pop() {

View File

@ -161,7 +161,7 @@ impl Deserializer for TokenDeserializer {
}
}
fn visit_named_unit<V>(&mut self, name: &str, visitor: V) -> Result<V::Value, Error>
fn visit_unit_struct<V>(&mut self, name: &str, visitor: V) -> Result<V::Value, Error>
where V: de::Visitor,
{
match self.tokens.peek() {
@ -178,7 +178,7 @@ impl Deserializer for TokenDeserializer {
}
}
fn visit_named_seq<V>(&mut self, name: &str, visitor: V) -> Result<V::Value, Error>
fn visit_tuple_struct<V>(&mut self, name: &str, visitor: V) -> Result<V::Value, Error>
where V: de::Visitor,
{
match self.tokens.peek() {
@ -195,7 +195,7 @@ impl Deserializer for TokenDeserializer {
}
}
fn visit_named_map<V>(&mut self, name: &str, visitor: V) -> Result<V::Value, Error>
fn visit_struct<V>(&mut self, name: &str, visitor: V) -> Result<V::Value, Error>
where V: de::Visitor,
{
match self.tokens.peek() {
@ -334,13 +334,13 @@ impl<'a> de::VariantVisitor for TokenDeserializerVariantVisitor<'a> {
//////////////////////////////////////////////////////////////////////////
#[derive(Copy, Clone, PartialEq, Debug, Deserialize)]
struct NamedUnit;
struct UnitStruct;
#[derive(PartialEq, Debug, Deserialize)]
struct NamedSeq(i32, i32, i32);
struct TupleStruct(i32, i32, i32);
#[derive(PartialEq, Debug, Deserialize)]
struct NamedMap {
struct Struct {
a: i32,
b: i32,
c: i32,
@ -498,19 +498,19 @@ declare_tests! {
Token::SeqEnd,
],
}
test_named_unit {
NamedUnit => vec![Token::Unit],
NamedUnit => vec![
Token::Name("NamedUnit"),
test_unit_struct {
UnitStruct => vec![Token::Unit],
UnitStruct => vec![
Token::Name("UnitStruct"),
Token::Unit,
],
NamedUnit => vec![
UnitStruct => vec![
Token::SeqStart(0),
Token::SeqEnd,
],
}
test_named_seq {
NamedSeq(1, 2, 3) => vec![
test_tuple_struct {
TupleStruct(1, 2, 3) => vec![
Token::SeqStart(3),
Token::SeqSep,
Token::I32(1),
@ -522,8 +522,8 @@ declare_tests! {
Token::I32(3),
Token::SeqEnd,
],
NamedSeq(1, 2, 3) => vec![
Token::Name("NamedSeq"),
TupleStruct(1, 2, 3) => vec![
Token::Name("TupleStruct"),
Token::SeqStart(3),
Token::SeqSep,
Token::I32(1),
@ -818,8 +818,8 @@ declare_tests! {
Token::MapEnd,
],
}
test_named_map {
NamedMap { a: 1, b: 2, c: 3 } => vec![
test_struct {
Struct { a: 1, b: 2, c: 3 } => vec![
Token::MapStart(3),
Token::MapSep,
Token::Str("a"),
@ -834,8 +834,8 @@ declare_tests! {
Token::I32(3),
Token::MapEnd,
],
NamedMap { a: 1, b: 2, c: 3 } => vec![
Token::Name("NamedMap"),
Struct { a: 1, b: 2, c: 3 } => vec![
Token::Name("Struct"),
Token::MapStart(3),
Token::MapSep,
Token::Str("a"),

View File

@ -24,17 +24,17 @@ pub enum Token<'a> {
Option(bool),
Unit,
NamedUnit(&'a str),
UnitStruct(&'a str),
EnumUnit(&'a str, &'a str),
SeqStart(Option<usize>),
NamedSeqStart(&'a str, Option<usize>),
TupleStructStart(&'a str, Option<usize>),
EnumSeqStart(&'a str, &'a str, Option<usize>),
SeqSep,
SeqEnd,
MapStart(Option<usize>),
NamedMapStart(&'a str, Option<usize>),
StructStart(&'a str, Option<usize>),
EnumMapStart(&'a str, &'a str, Option<usize>),
MapSep,
MapEnd,
@ -80,8 +80,8 @@ impl<'a> Serializer for AssertSerializer<'a> {
Ok(())
}
fn visit_named_unit(&mut self, name: &str) -> Result<(), ()> {
assert_eq!(self.iter.next().unwrap(), Token::NamedUnit(name));
fn visit_unit_struct(&mut self, name: &str) -> Result<(), ()> {
assert_eq!(self.iter.next().unwrap(), Token::UnitStruct(name));
Ok(())
}
@ -188,12 +188,12 @@ impl<'a> Serializer for AssertSerializer<'a> {
self.visit_sequence(visitor)
}
fn visit_named_seq<V>(&mut self, name: &str, visitor: V) -> Result<(), ()>
fn visit_tuple_struct<V>(&mut self, name: &str, visitor: V) -> Result<(), ()>
where V: SeqVisitor
{
let len = visitor.len();
assert_eq!(self.iter.next().unwrap(), Token::NamedSeqStart(name, len));
assert_eq!(self.iter.next().unwrap(), Token::TupleStructStart(name, len));
self.visit_sequence(visitor)
}
@ -228,12 +228,12 @@ impl<'a> Serializer for AssertSerializer<'a> {
self.visit_mapping(visitor)
}
fn visit_named_map<V>(&mut self, name: &str, visitor: V) -> Result<(), ()>
fn visit_struct<V>(&mut self, name: &str, visitor: V) -> Result<(), ()>
where V: MapVisitor
{
let len = visitor.len();
assert_eq!(self.iter.next().unwrap(), Token::NamedMapStart(name, len));
assert_eq!(self.iter.next().unwrap(), Token::StructStart(name, len));
self.visit_mapping(visitor)
}
@ -262,13 +262,13 @@ impl<'a> Serializer for AssertSerializer<'a> {
//////////////////////////////////////////////////////////////////////////
#[derive(Serialize)]
struct NamedUnit;
struct UnitStruct;
#[derive(Serialize)]
struct NamedSeq(i32, i32, i32);
struct TupleStruct(i32, i32, i32);
#[derive(Serialize)]
struct NamedMap {
struct Struct {
a: i32,
b: i32,
c: i32,
@ -480,12 +480,12 @@ declare_tests! {
Token::MapEnd,
],
}
test_named_unit {
NamedUnit => vec![Token::NamedUnit("NamedUnit")],
test_unit_struct {
UnitStruct => vec![Token::UnitStruct("UnitStruct")],
}
test_named_seq {
NamedSeq(1, 2, 3) => vec![
Token::NamedSeqStart("NamedSeq", Some(3)),
test_tuple_struct {
TupleStruct(1, 2, 3) => vec![
Token::TupleStructStart("TupleStruct", Some(3)),
Token::SeqSep,
Token::I32(1),
@ -497,9 +497,9 @@ declare_tests! {
Token::SeqEnd,
],
}
test_named_map {
NamedMap { a: 1, b: 2, c: 3 } => vec![
Token::NamedMapStart("NamedMap", Some(3)),
test_struct {
Struct { a: 1, b: 2, c: 3 } => vec![
Token::StructStart("Struct", Some(3)),
Token::MapSep,
Token::Str("a"),
Token::I32(1),