diff --git a/README.md b/README.md index b79648b2..f2377bbd 100644 --- a/README.md +++ b/README.md @@ -187,7 +187,7 @@ impl serde::Serialize for Point { fn serialize(&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(deserializer: &mut D) -> Result where D: serde::de::Deserializer { - deserializer.visit_named_map("Point", PointVisitor) + deserializer.visit_struct("Point", PointVisitor) } } diff --git a/serde/src/de/mod.rs b/serde/src/de/mod.rs index 253be30e..4aca837e 100644 --- a/serde/src/de/mod.rs +++ b/serde/src/de/mod.rs @@ -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(&mut self, _name: &str, visitor: V) -> Result + fn visit_unit_struct(&mut self, _name: &str, visitor: V) -> Result 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(&mut self, _name: &str, visitor: V) -> Result + fn visit_tuple_struct(&mut self, _name: &str, visitor: V) -> Result 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(&mut self, _name: &str, visitor: V) -> Result + fn visit_struct(&mut self, _name: &str, visitor: V) -> Result where V: Visitor, { self.visit_map(visitor) @@ -386,7 +386,7 @@ pub trait Visitor { } #[inline] - fn visit_named_unit(&mut self, _name: &str) -> Result + fn visit_unit_struct(&mut self, _name: &str) -> Result where E: Error, { self.visit_unit() diff --git a/serde/src/ser/mod.rs b/serde/src/ser/mod.rs index 1057901c..ecd2e82d 100644 --- a/serde/src/ser/mod.rs +++ b/serde/src/ser/mod.rs @@ -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(&mut self, + fn visit_tuple_struct(&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(&mut self, value: T) -> Result<(), Self::Error> + fn visit_tuple_struct_elt(&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(&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(&mut self, visitor: V) -> Result<(), Self::Error> @@ -190,7 +190,7 @@ pub trait Serializer { V: Serialize; #[inline] - fn visit_named_map(&mut self, + fn visit_struct(&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(&mut self, key: K, value: V) -> Result<(), Self::Error> + fn visit_struct_elt(&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. diff --git a/serde_codegen/src/de.rs b/serde_codegen/src/de.rs index 9d256a51..fa28528c 100644 --- a/serde_codegen/src/de.rs +++ b/serde_codegen/src/de.rs @@ -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) }) } diff --git a/serde_codegen/src/ser.rs b/serde_codegen/src/ser.rs index 656d5f31..32e05371 100644 --- a/serde_codegen/src/ser.rs +++ b/serde_codegen/src/ser.rs @@ -169,7 +169,7 @@ fn serialize_unit_struct( ) -> P { 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( Ok( Some( try!( - serializer.visit_named_map_elt( + serializer.visit_struct_elt( $key_expr, $value_expr, ) diff --git a/serde_tests/benches/bench_struct.rs b/serde_tests/benches/bench_struct.rs index fd52097b..ffd463ed 100644 --- a/serde_tests/benches/bench_struct.rs +++ b/serde_tests/benches/bench_struct.rs @@ -398,7 +398,7 @@ mod deserializer { } } - fn visit_named_map(&mut self, name: &str, mut visitor: V) -> Result + fn visit_struct(&mut self, name: &str, mut visitor: V) -> Result where V: de::Visitor, { match self.stack.pop() { diff --git a/serde_tests/tests/test_de.rs b/serde_tests/tests/test_de.rs index 7e1f2d98..037c0c52 100644 --- a/serde_tests/tests/test_de.rs +++ b/serde_tests/tests/test_de.rs @@ -161,7 +161,7 @@ impl Deserializer for TokenDeserializer { } } - fn visit_named_unit(&mut self, name: &str, visitor: V) -> Result + fn visit_unit_struct(&mut self, name: &str, visitor: V) -> Result where V: de::Visitor, { match self.tokens.peek() { @@ -178,7 +178,7 @@ impl Deserializer for TokenDeserializer { } } - fn visit_named_seq(&mut self, name: &str, visitor: V) -> Result + fn visit_tuple_struct(&mut self, name: &str, visitor: V) -> Result where V: de::Visitor, { match self.tokens.peek() { @@ -195,7 +195,7 @@ impl Deserializer for TokenDeserializer { } } - fn visit_named_map(&mut self, name: &str, visitor: V) -> Result + fn visit_struct(&mut self, name: &str, visitor: V) -> Result 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"), diff --git a/serde_tests/tests/test_ser.rs b/serde_tests/tests/test_ser.rs index 27644f45..a59ce726 100644 --- a/serde_tests/tests/test_ser.rs +++ b/serde_tests/tests/test_ser.rs @@ -24,17 +24,17 @@ pub enum Token<'a> { Option(bool), Unit, - NamedUnit(&'a str), + UnitStruct(&'a str), EnumUnit(&'a str, &'a str), SeqStart(Option), - NamedSeqStart(&'a str, Option), + TupleStructStart(&'a str, Option), EnumSeqStart(&'a str, &'a str, Option), SeqSep, SeqEnd, MapStart(Option), - NamedMapStart(&'a str, Option), + StructStart(&'a str, Option), EnumMapStart(&'a str, &'a str, Option), 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(&mut self, name: &str, visitor: V) -> Result<(), ()> + fn visit_tuple_struct(&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(&mut self, name: &str, visitor: V) -> Result<(), ()> + fn visit_struct(&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),