From 56c42a907f917e176c0580689ae9b29b09abf084 Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Thu, 8 Oct 2015 12:41:29 +0200 Subject: [PATCH] fix(#151): renaming Deserializer::visit_* to Deserializer::deserialize_* --- serde/src/bytes.rs | 6 +- serde/src/de/impls.rs | 50 +++++------ serde/src/de/mod.rs | 122 +++++++++++++------------- serde/src/de/value.rs | 26 +++--- serde/src/ser/impls.rs | 76 ++++++++--------- serde/src/ser/mod.rs | 180 +++++++++++++++++++-------------------- serde_codegen/src/de.rs | 12 +-- serde_codegen/src/ser.rs | 20 ++--- 8 files changed, 246 insertions(+), 246 deletions(-) diff --git a/serde/src/bytes.rs b/serde/src/bytes.rs index 6a51bf18..7d80ec2c 100644 --- a/serde/src/bytes.rs +++ b/serde/src/bytes.rs @@ -54,7 +54,7 @@ impl<'a> ser::Serialize for Bytes<'a> { fn serialize(&self, serializer: &mut S) -> Result<(), S::Error> where S: ser::Serializer { - serializer.visit_bytes(self.bytes) + serializer.serialize_bytes(self.bytes) } } @@ -140,7 +140,7 @@ impl ser::Serialize for ByteBuf { fn serialize(&self, serializer: &mut S) -> Result<(), S::Error> where S: ser::Serializer { - serializer.visit_bytes(&self) + serializer.serialize_bytes(&self) } } @@ -199,7 +199,7 @@ impl de::Deserialize for ByteBuf { fn deserialize(deserializer: &mut D) -> Result where D: de::Deserializer { - deserializer.visit_bytes(ByteBufVisitor) + deserializer.deserialize_bytes(ByteBufVisitor) } } diff --git a/serde/src/de/impls.rs b/serde/src/de/impls.rs index 2ae1d5bf..731d1e88 100644 --- a/serde/src/de/impls.rs +++ b/serde/src/de/impls.rs @@ -64,7 +64,7 @@ impl Deserialize for () { fn deserialize(deserializer: &mut D) -> Result<(), D::Error> where D: Deserializer, { - deserializer.visit_unit(UnitVisitor) + deserializer.deserialize_unit(UnitVisitor) } } @@ -97,7 +97,7 @@ impl Deserialize for bool { fn deserialize(deserializer: &mut D) -> Result where D: Deserializer, { - deserializer.visit_bool(BoolVisitor) + deserializer.deserialize_bool(BoolVisitor) } } @@ -171,18 +171,18 @@ macro_rules! impl_deserialize_num { } } -impl_deserialize_num!(isize, visit_isize); -impl_deserialize_num!(i8, visit_i8); -impl_deserialize_num!(i16, visit_i16); -impl_deserialize_num!(i32, visit_i32); -impl_deserialize_num!(i64, visit_i64); -impl_deserialize_num!(usize, visit_usize); -impl_deserialize_num!(u8, visit_u8); -impl_deserialize_num!(u16, visit_u16); -impl_deserialize_num!(u32, visit_u32); -impl_deserialize_num!(u64, visit_u64); -impl_deserialize_num!(f32, visit_f32); -impl_deserialize_num!(f64, visit_f64); +impl_deserialize_num!(isize, deserialize_isize); +impl_deserialize_num!(i8, deserialize_i8); +impl_deserialize_num!(i16, deserialize_i16); +impl_deserialize_num!(i32, deserialize_i32); +impl_deserialize_num!(i64, deserialize_i64); +impl_deserialize_num!(usize, deserialize_usize); +impl_deserialize_num!(u8, deserialize_u8); +impl_deserialize_num!(u16, deserialize_u16); +impl_deserialize_num!(u32, deserialize_u32); +impl_deserialize_num!(u64, deserialize_u64); +impl_deserialize_num!(f32, deserialize_f32); +impl_deserialize_num!(f64, deserialize_f64); /////////////////////////////////////////////////////////////////////////////// @@ -220,7 +220,7 @@ impl Deserialize for char { fn deserialize(deserializer: &mut D) -> Result where D: Deserializer, { - deserializer.visit_char(CharVisitor) + deserializer.deserialize_char(CharVisitor) } } @@ -266,7 +266,7 @@ impl Deserialize for String { fn deserialize(deserializer: &mut D) -> Result where D: Deserializer, { - deserializer.visit_string(StringVisitor) + deserializer.deserialize_string(StringVisitor) } } @@ -300,7 +300,7 @@ impl Deserialize for Option where T: Deserialize { fn deserialize(deserializer: &mut D) -> Result, D::Error> where D: Deserializer, { - deserializer.visit_option(OptionVisitor { marker: PhantomData }) + deserializer.deserialize_option(OptionVisitor { marker: PhantomData }) } } @@ -364,7 +364,7 @@ macro_rules! seq_impl { fn deserialize(deserializer: &mut D) -> Result<$ty, D::Error> where D: Deserializer, { - deserializer.visit_seq($visitor_name::new()) + deserializer.deserialize_seq($visitor_name::new()) } } } @@ -474,7 +474,7 @@ impl Deserialize for [T; 0] fn deserialize(deserializer: &mut D) -> Result<[T; 0], D::Error> where D: Deserializer, { - deserializer.visit_seq(ArrayVisitor0::new()) + deserializer.deserialize_seq(ArrayVisitor0::new()) } } @@ -520,7 +520,7 @@ macro_rules! array_impls { fn deserialize(deserializer: &mut D) -> Result<[T; $len], D::Error> where D: Deserializer, { - deserializer.visit_seq($visitor::new()) + deserializer.deserialize_seq($visitor::new()) } } )+ @@ -621,7 +621,7 @@ macro_rules! tuple_impls { fn deserialize(deserializer: &mut D) -> Result<($($name,)+), D::Error> where D: Deserializer, { - deserializer.visit_tuple($len, $visitor::new()) + deserializer.deserialize_tuple($len, $visitor::new()) } } )+ @@ -705,7 +705,7 @@ macro_rules! map_impl { fn deserialize(deserializer: &mut D) -> Result<$ty, D::Error> where D: Deserializer, { - deserializer.visit_map($visitor_name::new()) + deserializer.deserialize_map($visitor_name::new()) } } } @@ -753,7 +753,7 @@ impl Deserialize for path::PathBuf { fn deserialize(deserializer: &mut D) -> Result where D: Deserializer, { - deserializer.visit(PathBufVisitor) + deserializer.deserialize(PathBufVisitor) } } @@ -862,7 +862,7 @@ impl Deserialize for Result where T: Deserialize, E: Deserialize { } } - deserializer.visit(FieldVisitor) + deserializer.deserialize(FieldVisitor) } } @@ -892,6 +892,6 @@ impl Deserialize for Result where T: Deserialize, E: Deserialize { const VARIANTS: &'static [&'static str] = &["Ok", "Err"]; - deserializer.visit_enum("Result", VARIANTS, Visitor(PhantomData)) + deserializer.deserialize_enum("Result", VARIANTS, Visitor(PhantomData)) } } diff --git a/serde/src/de/mod.rs b/serde/src/de/mod.rs index b078cde9..1dc27313 100644 --- a/serde/src/de/mod.rs +++ b/serde/src/de/mod.rs @@ -140,247 +140,247 @@ pub trait Deserialize: Sized { /// `Deserializer` is a trait that can deserialize values by threading a `Visitor` trait through a /// value. It supports two entry point styles which enables different kinds of deserialization. /// -/// 1) The `visit` method. File formats like JSON embed the type of it's construct in it's file +/// 1) The `deserialize` method. File formats like JSON embed the type of its construct in its file /// format. This allows the `Deserializer` to deserialize into a generic type like /// `json::Value`, which can represent all JSON types. /// -/// 2) The `visit_*` methods. File formats like bincode do not embed in it's format how to decode -/// it's values. It relies instead on the `Deserialize` type to hint to the `Deserializer` with -/// the `visit_*` methods how it should parse the next value. One downside though to only -/// supporting the `visit_*` types is that it does not allow for deserializing into a generic -/// `json::Value`-esque type. +/// 2) The `deserialize_*` methods. File formats like bincode do not embed in its format how to +/// decode its values. It relies instead on the `Deserialize` type to hint to the `Deserializer` +/// with the `deserialize_*` methods how it should parse the next value. One downside though to +/// only supporting the `deserialize_*` types is that it does not allow for deserializing into a +/// generic `json::Value`-esque type. pub trait Deserializer { /// The error type that can be returned if some error occurs during deserialization. type Error: Error; /// This method walks a visitor through a value as it is being deserialized. - fn visit(&mut self, visitor: V) -> Result + fn deserialize(&mut self, visitor: V) -> Result where V: Visitor; /// This method hints that the `Deserialize` type is expecting a `bool` value. #[inline] - fn visit_bool(&mut self, visitor: V) -> Result + fn deserialize_bool(&mut self, visitor: V) -> Result where V: Visitor, { - self.visit(visitor) + self.deserialize(visitor) } /// This method hints that the `Deserialize` type is expecting an `usize` value. #[inline] - fn visit_usize(&mut self, visitor: V) -> Result + fn deserialize_usize(&mut self, visitor: V) -> Result where V: Visitor, { - self.visit_u64(visitor) + self.deserialize_u64(visitor) } /// This method hints that the `Deserialize` type is expecting an `u8` value. #[inline] - fn visit_u8(&mut self, visitor: V) -> Result + fn deserialize_u8(&mut self, visitor: V) -> Result where V: Visitor, { - self.visit_u64(visitor) + self.deserialize_u64(visitor) } /// This method hints that the `Deserialize` type is expecting an `u16` value. #[inline] - fn visit_u16(&mut self, visitor: V) -> Result + fn deserialize_u16(&mut self, visitor: V) -> Result where V: Visitor, { - self.visit_u64(visitor) + self.deserialize_u64(visitor) } /// This method hints that the `Deserialize` type is expecting an `u32` value. #[inline] - fn visit_u32(&mut self, visitor: V) -> Result + fn deserialize_u32(&mut self, visitor: V) -> Result where V: Visitor, { - self.visit_u64(visitor) + self.deserialize_u64(visitor) } /// This method hints that the `Deserialize` type is expecting an `u64` value. #[inline] - fn visit_u64(&mut self, visitor: V) -> Result + fn deserialize_u64(&mut self, visitor: V) -> Result where V: Visitor, { - self.visit(visitor) + self.deserialize(visitor) } /// This method hints that the `Deserialize` type is expecting an `isize` value. #[inline] - fn visit_isize(&mut self, visitor: V) -> Result + fn deserialize_isize(&mut self, visitor: V) -> Result where V: Visitor, { - self.visit_i64(visitor) + self.deserialize_i64(visitor) } /// This method hints that the `Deserialize` type is expecting an `i8` value. #[inline] - fn visit_i8(&mut self, visitor: V) -> Result + fn deserialize_i8(&mut self, visitor: V) -> Result where V: Visitor, { - self.visit_i64(visitor) + self.deserialize_i64(visitor) } /// This method hints that the `Deserialize` type is expecting an `i16` value. #[inline] - fn visit_i16(&mut self, visitor: V) -> Result + fn deserialize_i16(&mut self, visitor: V) -> Result where V: Visitor, { - self.visit_i64(visitor) + self.deserialize_i64(visitor) } /// This method hints that the `Deserialize` type is expecting an `i32` value. #[inline] - fn visit_i32(&mut self, visitor: V) -> Result + fn deserialize_i32(&mut self, visitor: V) -> Result where V: Visitor, { - self.visit_i64(visitor) + self.deserialize_i64(visitor) } /// This method hints that the `Deserialize` type is expecting an `i64` value. #[inline] - fn visit_i64(&mut self, visitor: V) -> Result + fn deserialize_i64(&mut self, visitor: V) -> Result where V: Visitor, { - self.visit(visitor) + self.deserialize(visitor) } /// This method hints that the `Deserialize` type is expecting a `f32` value. #[inline] - fn visit_f32(&mut self, visitor: V) -> Result + fn deserialize_f32(&mut self, visitor: V) -> Result where V: Visitor, { - self.visit_f64(visitor) + self.deserialize_f64(visitor) } /// This method hints that the `Deserialize` type is expecting a `f64` value. #[inline] - fn visit_f64(&mut self, visitor: V) -> Result + fn deserialize_f64(&mut self, visitor: V) -> Result where V: Visitor, { - self.visit(visitor) + self.deserialize(visitor) } /// This method hints that the `Deserialize` type is expecting a `char` value. #[inline] - fn visit_char(&mut self, visitor: V) -> Result + fn deserialize_char(&mut self, visitor: V) -> Result where V: Visitor, { - self.visit(visitor) + self.deserialize(visitor) } /// This method hints that the `Deserialize` type is expecting a `&str` value. #[inline] - fn visit_str(&mut self, visitor: V) -> Result + fn deserialize_str(&mut self, visitor: V) -> Result where V: Visitor, { - self.visit(visitor) + self.deserialize(visitor) } /// This method hints that the `Deserialize` type is expecting a `String` value. #[inline] - fn visit_string(&mut self, visitor: V) -> Result + fn deserialize_string(&mut self, visitor: V) -> Result where V: Visitor, { - self.visit_str(visitor) + self.deserialize_str(visitor) } /// This method hints that the `Deserialize` type is expecting an `unit` value. #[inline] - fn visit_unit(&mut self, visitor: V) -> Result + fn deserialize_unit(&mut self, visitor: V) -> Result where V: Visitor, { - self.visit(visitor) + self.deserialize(visitor) } /// This method hints that the `Deserialize` type is expecting an `Option` value. This allows /// deserializers that encode an optional value as a nullable value to convert the null value /// into a `None`, and a regular value as `Some(value)`. #[inline] - fn visit_option(&mut self, visitor: V) -> Result + fn deserialize_option(&mut self, visitor: V) -> Result where V: Visitor, { - self.visit(visitor) + self.deserialize(visitor) } /// This method hints that the `Deserialize` type is expecting a sequence value. This allows /// deserializers to parse sequences that aren't tagged as sequences. #[inline] - fn visit_seq(&mut self, visitor: V) -> Result + fn deserialize_seq(&mut self, visitor: V) -> Result where V: Visitor, { - self.visit(visitor) + self.deserialize(visitor) } /// This method hints that the `Deserialize` type is expecting a map of values. This allows /// deserializers to parse sequences that aren't tagged as maps. #[inline] - fn visit_map(&mut self, visitor: V) -> Result + fn deserialize_map(&mut self, visitor: V) -> Result where V: Visitor, { - self.visit(visitor) + self.deserialize(visitor) } /// This method hints that the `Deserialize` type is expecting a unit struct. This allows /// deserializers to a unit struct that aren't tagged as a unit struct. #[inline] - fn visit_unit_struct(&mut self, + fn deserialize_unit_struct(&mut self, _name: &'static str, visitor: V) -> Result where V: Visitor, { - self.visit_unit(visitor) + self.deserialize_unit(visitor) } /// This method hints that the `Deserialize` type is expecting a newtype struct. This allows /// deserializers to a newtype struct that aren't tagged as a newtype struct. #[inline] - fn visit_newtype_struct(&mut self, + fn deserialize_newtype_struct(&mut self, name: &'static str, visitor: V) -> Result where V: Visitor, { - self.visit_tuple_struct(name, 1, visitor) + self.deserialize_tuple_struct(name, 1, visitor) } /// 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_tuple_struct(&mut self, + fn deserialize_tuple_struct(&mut self, _name: &'static str, len: usize, visitor: V) -> Result where V: Visitor, { - self.visit_tuple(len, visitor) + self.deserialize_tuple(len, visitor) } /// 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_struct(&mut self, + fn deserialize_struct(&mut self, _name: &'static str, _fields: &'static [&'static str], visitor: V) -> Result where V: Visitor, { - self.visit_map(visitor) + self.deserialize_map(visitor) } /// This method hints that the `Deserialize` type is expecting a tuple value. This allows /// deserializers that provide a custom tuple serialization to properly deserialize the type. #[inline] - fn visit_tuple(&mut self, _len: usize, visitor: V) -> Result + fn deserialize_tuple(&mut self, _len: usize, visitor: V) -> Result where V: Visitor, { - self.visit_seq(visitor) + self.deserialize_seq(visitor) } /// This method hints that the `Deserialize` type is expecting an enum value. This allows /// deserializers that provide a custom enumeration serialization to properly deserialize the /// type. #[inline] - fn visit_enum(&mut self, + fn deserialize_enum(&mut self, _enum: &'static str, _variants: &'static [&'static str], _visitor: V) -> Result @@ -393,10 +393,10 @@ pub trait Deserializer { /// deserializers that provide a custom byte vector serialization to properly deserialize the /// type. #[inline] - fn visit_bytes(&mut self, visitor: V) -> Result + fn deserialize_bytes(&mut self, visitor: V) -> Result where V: Visitor, { - self.visit_seq(visitor) + self.deserialize_seq(visitor) } /// Specify a format string for the deserializer. @@ -686,7 +686,7 @@ pub trait MapVisitor { (0, None) } - /// Report that there + /// Report that the struct has a field that wasn't deserialized fn missing_field(&mut self, field: &'static str) -> Result where V: Deserialize, { diff --git a/serde/src/de/value.rs b/serde/src/de/value.rs index 0a5fe4fc..5f5ee9aa 100644 --- a/serde/src/de/value.rs +++ b/serde/src/de/value.rs @@ -81,13 +81,13 @@ impl de::Deserializer for UnitDeserializer { type Error = E; - fn visit(&mut self, mut visitor: V) -> Result + fn deserialize(&mut self, mut visitor: V) -> Result where V: de::Visitor, { visitor.visit_unit() } - fn visit_option(&mut self, mut visitor: V) -> Result + fn deserialize_option(&mut self, mut visitor: V) -> Result where V: de::Visitor, { visitor.visit_none() @@ -116,7 +116,7 @@ macro_rules! primitive_deserializer { { type Error = E; - fn visit(&mut self, mut visitor: V) -> Result + fn deserialize(&mut self, mut visitor: V) -> Result where V: de::Visitor, { match self.0.take() { @@ -163,7 +163,7 @@ impl<'a, E> de::Deserializer for StrDeserializer<'a, E> { type Error = E; - fn visit(&mut self, mut visitor: V) -> Result + fn deserialize(&mut self, mut visitor: V) -> Result where V: de::Visitor, { match self.0.take() { @@ -172,7 +172,7 @@ impl<'a, E> de::Deserializer for StrDeserializer<'a, E> } } - fn visit_enum(&mut self, + fn deserialize_enum(&mut self, _name: &str, _variants: &'static [&'static str], mut visitor: V) -> Result @@ -218,7 +218,7 @@ impl de::Deserializer for StringDeserializer { type Error = E; - fn visit(&mut self, mut visitor: V) -> Result + fn deserialize(&mut self, mut visitor: V) -> Result where V: de::Visitor, { match self.0.take() { @@ -227,7 +227,7 @@ impl de::Deserializer for StringDeserializer } } - fn visit_enum(&mut self, + fn deserialize_enum(&mut self, _name: &str, _variants: &'static [&'static str], mut visitor: V) -> Result @@ -282,7 +282,7 @@ impl de::Deserializer for SeqDeserializer { type Error = E; - fn visit(&mut self, mut visitor: V) -> Result + fn deserialize(&mut self, mut visitor: V) -> Result where V: de::Visitor, { visitor.visit_seq(self) @@ -387,7 +387,7 @@ impl de::Deserializer for SeqVisitorDeserializer { type Error = E; - fn visit(&mut self, mut visitor: V) -> Result { + fn deserialize(&mut self, mut visitor: V) -> Result { visitor.visit_seq(&mut self.visitor) } } @@ -432,7 +432,7 @@ impl de::Deserializer for MapDeserializer { type Error = E; - fn visit(&mut self, mut visitor: V_) -> Result + fn deserialize(&mut self, mut visitor: V_) -> Result where V_: de::Visitor, { visitor.visit_map(self) @@ -541,7 +541,7 @@ impl de::Deserializer for MapVisitorDeserializer { type Error = E; - fn visit(&mut self, mut visitor: V) -> Result { + fn deserialize(&mut self, mut visitor: V) -> Result { visitor.visit_map(&mut self.visitor) } } @@ -566,7 +566,7 @@ impl<'a, E> de::Deserializer for BytesDeserializer<'a, E> { type Error = E; - fn visit(&mut self, mut visitor: V) -> Result + fn deserialize(&mut self, mut visitor: V) -> Result where V: de::Visitor, { match self.0.take() { @@ -597,7 +597,7 @@ impl de::Deserializer for ByteBufDeserializer { type Error = E; - fn visit(&mut self, mut visitor: V) -> Result + fn deserialize(&mut self, mut visitor: V) -> Result where V: de::Visitor, { match self.0.take() { diff --git a/serde/src/ser/impls.rs b/serde/src/ser/impls.rs index 63aea2ec..b1cffb13 100644 --- a/serde/src/ser/impls.rs +++ b/serde/src/ser/impls.rs @@ -48,20 +48,20 @@ macro_rules! impl_visit { } } -impl_visit!(bool, visit_bool); -impl_visit!(isize, visit_isize); -impl_visit!(i8, visit_i8); -impl_visit!(i16, visit_i16); -impl_visit!(i32, visit_i32); -impl_visit!(i64, visit_i64); -impl_visit!(usize, visit_usize); -impl_visit!(u8, visit_u8); -impl_visit!(u16, visit_u16); -impl_visit!(u32, visit_u32); -impl_visit!(u64, visit_u64); -impl_visit!(f32, visit_f32); -impl_visit!(f64, visit_f64); -impl_visit!(char, visit_char); +impl_visit!(bool, serialize_bool); +impl_visit!(isize, serialize_isize); +impl_visit!(i8, serialize_i8); +impl_visit!(i16, serialize_i16); +impl_visit!(i32, serialize_i32); +impl_visit!(i64, serialize_i64); +impl_visit!(usize, serialize_usize); +impl_visit!(u8, serialize_u8); +impl_visit!(u16, serialize_u16); +impl_visit!(u32, serialize_u32); +impl_visit!(u64, serialize_u64); +impl_visit!(f32, serialize_f32); +impl_visit!(f64, serialize_f64); +impl_visit!(char, serialize_char); /////////////////////////////////////////////////////////////////////////////// @@ -70,7 +70,7 @@ impl Serialize for str { fn serialize(&self, serializer: &mut S) -> Result<(), S::Error> where S: Serializer, { - serializer.visit_str(self) + serializer.serialize_str(self) } } @@ -91,8 +91,8 @@ impl Serialize for Option where T: Serialize { where S: Serializer, { match *self { - Some(ref value) => serializer.visit_some(value), - None => serializer.visit_none(), + Some(ref value) => serializer.serialize_some(value), + None => serializer.serialize_none(), } } } @@ -104,7 +104,7 @@ impl SeqVisitor for Option where T: Serialize { { match self.take() { Some(value) => { - try!(serializer.visit_seq_elt(value)); + try!(serializer.serialize_seq_elt(value)); Ok(Some(())) } None => Ok(None), @@ -133,7 +133,7 @@ impl SeqVisitor for Option where T: Serialize { /// fn serialize(&self, ser: &mut S) -> Result<(), S::Error> /// where S: Serializer, /// { -/// ser.visit_seq(SeqIteratorVisitor::new( +/// ser.serialize_seq(SeqIteratorVisitor::new( /// self.0.iter(), /// Some(self.0.len()), /// )) @@ -168,7 +168,7 @@ impl SeqVisitor for SeqIteratorVisitor { match self.iter.next() { Some(value) => { - try!(serializer.visit_seq_elt(value)); + try!(serializer.serialize_seq_elt(value)); Ok(Some(())) } None => Ok(None), @@ -190,7 +190,7 @@ impl Serialize for [T] fn serialize(&self, serializer: &mut S) -> Result<(), S::Error> where S: Serializer, { - serializer.visit_seq(SeqIteratorVisitor::new(self.iter(), Some(self.len()))) + serializer.serialize_seq(SeqIteratorVisitor::new(self.iter(), Some(self.len()))) } } @@ -201,7 +201,7 @@ macro_rules! array_impls { fn serialize(&self, serializer: &mut S) -> Result<(), S::Error> where S: Serializer, { - serializer.visit_seq(SeqIteratorVisitor::new(self.iter(), Some($len))) + serializer.serialize_seq(SeqIteratorVisitor::new(self.iter(), Some($len))) } } } @@ -250,7 +250,7 @@ impl Serialize for BinaryHeap fn serialize(&self, serializer: &mut S) -> Result<(), S::Error> where S: Serializer, { - serializer.visit_seq(SeqIteratorVisitor::new(self.iter(), Some(self.len()))) + serializer.serialize_seq(SeqIteratorVisitor::new(self.iter(), Some(self.len()))) } } @@ -261,7 +261,7 @@ impl Serialize for BTreeSet fn serialize(&self, serializer: &mut S) -> Result<(), S::Error> where S: Serializer, { - serializer.visit_seq(SeqIteratorVisitor::new(self.iter(), Some(self.len()))) + serializer.serialize_seq(SeqIteratorVisitor::new(self.iter(), Some(self.len()))) } } @@ -273,7 +273,7 @@ impl Serialize for EnumSet fn serialize(&self, serializer: &mut S) -> Result<(), S::Error> where S: Serializer, { - serializer.visit_seq(SeqIteratorVisitor::new(self.iter(), Some(self.len()))) + serializer.serialize_seq(SeqIteratorVisitor::new(self.iter(), Some(self.len()))) } } @@ -284,7 +284,7 @@ impl Serialize for HashSet fn serialize(&self, serializer: &mut S) -> Result<(), S::Error> where S: Serializer, { - serializer.visit_seq(SeqIteratorVisitor::new(self.iter(), Some(self.len()))) + serializer.serialize_seq(SeqIteratorVisitor::new(self.iter(), Some(self.len()))) } } @@ -295,7 +295,7 @@ impl Serialize for LinkedList fn serialize(&self, serializer: &mut S) -> Result<(), S::Error> where S: Serializer, { - serializer.visit_seq(SeqIteratorVisitor::new(self.iter(), Some(self.len()))) + serializer.serialize_seq(SeqIteratorVisitor::new(self.iter(), Some(self.len()))) } } @@ -309,7 +309,7 @@ impl Serialize for ops::Range where S: Serializer, { let len = iter::Step::steps_between(&self.start, &self.end, &A::one()); - serializer.visit_seq(SeqIteratorVisitor::new(self.clone(), len)) + serializer.serialize_seq(SeqIteratorVisitor::new(self.clone(), len)) } } @@ -327,7 +327,7 @@ impl Serialize for VecDeque where T: Serialize { fn serialize(&self, serializer: &mut S) -> Result<(), S::Error> where S: Serializer, { - serializer.visit_seq(SeqIteratorVisitor::new(self.iter(), Some(self.len()))) + serializer.serialize_seq(SeqIteratorVisitor::new(self.iter(), Some(self.len()))) } } @@ -338,7 +338,7 @@ impl Serialize for () { fn serialize(&self, serializer: &mut S) -> Result<(), S::Error> where S: Serializer, { - serializer.visit_unit() + serializer.serialize_unit() } } @@ -382,7 +382,7 @@ macro_rules! tuple_impls { $( $state => { self.state += 1; - Ok(Some(try!(serializer.visit_tuple_elt(&e!(self.tuple.$idx))))) + Ok(Some(try!(serializer.serialize_tuple_elt(&e!(self.tuple.$idx))))) } )+ _ => { @@ -401,7 +401,7 @@ macro_rules! tuple_impls { { #[inline] fn serialize(&self, serializer: &mut S) -> Result<(), S::Error> { - serializer.visit_tuple($TupleVisitor::new(self)) + serializer.serialize_tuple($TupleVisitor::new(self)) } } )+ @@ -530,7 +530,7 @@ tuple_impls! { /// fn serialize(&self, ser: &mut S) -> Result<(), S::Error> /// where S: Serializer, /// { -/// ser.visit_map(MapIteratorVisitor::new( +/// ser.serialize_map(MapIteratorVisitor::new( /// self.0.iter(), /// Some(self.0.len()), /// )) @@ -566,7 +566,7 @@ impl MapVisitor for MapIteratorVisitor { match self.iter.next() { Some((key, value)) => { - let value = try!(serializer.visit_map_elt(key, value)); + let value = try!(serializer.serialize_map_elt(key, value)); Ok(Some(value)) } None => Ok(None) @@ -589,7 +589,7 @@ impl Serialize for BTreeMap fn serialize(&self, serializer: &mut S) -> Result<(), S::Error> where S: Serializer, { - serializer.visit_map(MapIteratorVisitor::new(self.iter(), Some(self.len()))) + serializer.serialize_map(MapIteratorVisitor::new(self.iter(), Some(self.len()))) } } @@ -601,7 +601,7 @@ impl Serialize for HashMap fn serialize(&self, serializer: &mut S) -> Result<(), S::Error> where S: Serializer, { - serializer.visit_map(MapIteratorVisitor::new(self.iter(), Some(self.len()))) + serializer.serialize_map(MapIteratorVisitor::new(self.iter(), Some(self.len()))) } } @@ -667,10 +667,10 @@ impl Serialize for Result where T: Serialize, E: Serialize { fn serialize(&self, serializer: &mut S) -> Result<(), S::Error> where S: Serializer { match *self { Result::Ok(ref value) => { - serializer.visit_newtype_variant("Result", 0, "Ok", value) + serializer.serialize_newtype_variant("Result", 0, "Ok", value) } Result::Err(ref value) => { - serializer.visit_newtype_variant("Result", 1, "Err", value) + serializer.serialize_newtype_variant("Result", 1, "Err", value) } } } diff --git a/serde/src/ser/mod.rs b/serde/src/ser/mod.rs index 7dc9b1de..06fa7bb8 100644 --- a/serde/src/ser/mod.rs +++ b/serde/src/ser/mod.rs @@ -18,247 +18,247 @@ pub trait Serializer { /// The error type that can be returned if some error occurs during serialization. type Error; - /// `visit_bool` serializes a `bool` value. - fn visit_bool(&mut self, v: bool) -> Result<(), Self::Error>; + /// Serializes a `bool` value. + fn serialize_bool(&mut self, v: bool) -> Result<(), Self::Error>; - /// `visit_isize` serializes a `isize` value. By default it casts the value to a `i64` and - /// passes it to the `visit_i64` method. + /// Serializes a `isize` value. By default it casts the value to a `i64` and + /// passes it to the `serialize_i64` method. #[inline] - fn visit_isize(&mut self, v: isize) -> Result<(), Self::Error> { - self.visit_i64(v as i64) + fn serialize_isize(&mut self, v: isize) -> Result<(), Self::Error> { + self.serialize_i64(v as i64) } - /// `visit_i8` serializes a `i8` value. By default it casts the value to a `i64` and - /// passes it to the `visit_i64` method. + /// Serializes a `i8` value. By default it casts the value to a `i64` and + /// passes it to the `serialize_i64` method. #[inline] - fn visit_i8(&mut self, v: i8) -> Result<(), Self::Error> { - self.visit_i64(v as i64) + fn serialize_i8(&mut self, v: i8) -> Result<(), Self::Error> { + self.serialize_i64(v as i64) } - /// `visit_i16` serializes a `i16` value. By default it casts the value to a `i64` and - /// passes it to the `visit_i64` method. + /// Serializes a `i16` value. By default it casts the value to a `i64` and + /// passes it to the `serialize_i64` method. #[inline] - fn visit_i16(&mut self, v: i16) -> Result<(), Self::Error> { - self.visit_i64(v as i64) + fn serialize_i16(&mut self, v: i16) -> Result<(), Self::Error> { + self.serialize_i64(v as i64) } - /// `visit_i32` serializes a `i32` value. By default it casts the value to a `i64` and - /// passes it to the `visit_i64` method. + /// Serializes a `i32` value. By default it casts the value to a `i64` and + /// passes it to the `serialize_i64` method. #[inline] - fn visit_i32(&mut self, v: i32) -> Result<(), Self::Error> { - self.visit_i64(v as i64) + fn serialize_i32(&mut self, v: i32) -> Result<(), Self::Error> { + self.serialize_i64(v as i64) } - /// `visit_i64` serializes a `i64` value. + /// Serializes a `i64` value. #[inline] - fn visit_i64(&mut self, v: i64) -> Result<(), Self::Error>; + fn serialize_i64(&mut self, v: i64) -> Result<(), Self::Error>; - /// `visit_usize` serializes a `usize` value. By default it casts the value to a `u64` and - /// passes it to the `visit_u64` method. + /// Serializes a `usize` value. By default it casts the value to a `u64` and + /// passes it to the `serialize_u64` method. #[inline] - fn visit_usize(&mut self, v: usize) -> Result<(), Self::Error> { - self.visit_u64(v as u64) + fn serialize_usize(&mut self, v: usize) -> Result<(), Self::Error> { + self.serialize_u64(v as u64) } - /// `visit_u8` serializes a `u8` value. By default it casts the value to a `u64` and passes - /// it to the `visit_u64` method. + /// Serializes a `u8` value. By default it casts the value to a `u64` and passes + /// it to the `serialize_u64` method. #[inline] - fn visit_u8(&mut self, v: u8) -> Result<(), Self::Error> { - self.visit_u64(v as u64) + fn serialize_u8(&mut self, v: u8) -> Result<(), Self::Error> { + self.serialize_u64(v as u64) } - /// `visit_u32` serializes a `u32` value. By default it casts the value to a `u64` and passes - /// it to the `visit_u64` method. + /// Serializes a `u32` value. By default it casts the value to a `u64` and passes + /// it to the `serialize_u64` method. #[inline] - fn visit_u16(&mut self, v: u16) -> Result<(), Self::Error> { - self.visit_u64(v as u64) + fn serialize_u16(&mut self, v: u16) -> Result<(), Self::Error> { + self.serialize_u64(v as u64) } - /// `visit_u32` serializes a `u32` value. By default it casts the value to a `u64` and passes - /// it to the `visit_u64` method. + /// Serializes a `u32` value. By default it casts the value to a `u64` and passes + /// it to the `serialize_u64` method. #[inline] - fn visit_u32(&mut self, v: u32) -> Result<(), Self::Error> { - self.visit_u64(v as u64) + fn serialize_u32(&mut self, v: u32) -> Result<(), Self::Error> { + self.serialize_u64(v as u64) } - /// `visit_u64` serializes a `u64` value. + /// `Serializes a `u64` value. #[inline] - fn visit_u64(&mut self, v: u64) -> Result<(), Self::Error>; + fn serialize_u64(&mut self, v: u64) -> Result<(), Self::Error>; - /// `visit_f32` serializes a `f32` value. By default it casts the value to a `f64` and passes - /// it to the `visit_f64` method. + /// Serializes a `f32` value. By default it casts the value to a `f64` and passes + /// it to the `serialize_f64` method. #[inline] - fn visit_f32(&mut self, v: f32) -> Result<(), Self::Error> { - self.visit_f64(v as f64) + fn serialize_f32(&mut self, v: f32) -> Result<(), Self::Error> { + self.serialize_f64(v as f64) } - /// `visit_f64` serializes a `f64` value. - fn visit_f64(&mut self, v: f64) -> Result<(), Self::Error>; + /// Serializes a `f64` value. + fn serialize_f64(&mut self, v: f64) -> Result<(), Self::Error>; - /// `visit_char` serializes a character. By default it serializes it as a `&str` containing a + /// Serializes a character. By default it serializes it as a `&str` containing a /// single character. #[inline] - fn visit_char(&mut self, v: char) -> Result<(), Self::Error> { + fn serialize_char(&mut self, v: char) -> Result<(), Self::Error> { // FIXME: this allocation is required in order to be compatible with stable rust, which // doesn't support encoding a `char` into a stack buffer. - self.visit_str(&v.to_string()) + self.serialize_str(&v.to_string()) } - /// `visit_str` serializes a `&str`. - fn visit_str(&mut self, value: &str) -> Result<(), Self::Error>; + /// Serializes a `&str`. + fn serialize_str(&mut self, value: &str) -> Result<(), Self::Error>; - /// `visit_bytes` is a hook that enables those serialization formats that support serializing + /// Enables those serialization formats that support serializing /// byte slices separately from generic arrays. By default it serializes as a regular array. #[inline] - fn visit_bytes(&mut self, value: &[u8]) -> Result<(), Self::Error> { - self.visit_seq(impls::SeqIteratorVisitor::new(value.iter(), Some(value.len()))) + fn serialize_bytes(&mut self, value: &[u8]) -> Result<(), Self::Error> { + self.serialize_seq(impls::SeqIteratorVisitor::new(value.iter(), Some(value.len()))) } /// Serializes a `()` value. - fn visit_unit(&mut self) -> Result<(), Self::Error>; + fn serialize_unit(&mut self) -> Result<(), Self::Error>; /// Serializes a unit struct value. /// /// By default, unit structs are serialized as a `()`. #[inline] - fn visit_unit_struct(&mut self, _name: &'static str) -> Result<(), Self::Error> { - self.visit_unit() + fn serialize_unit_struct(&mut self, _name: &'static str) -> Result<(), Self::Error> { + self.serialize_unit() } /// Serializes a unit variant, otherwise known as a variant with no arguments. /// /// By default, unit variants are serialized as a `()`. #[inline] - fn visit_unit_variant(&mut self, + fn serialize_unit_variant(&mut self, _name: &'static str, _variant_index: usize, _variant: &'static str) -> Result<(), Self::Error> { - self.visit_unit() + self.serialize_unit() } - /// The `visit_newtype_struct` allows a tuple struct with a single element, also known as a + /// Allows a tuple struct with a single element, also known as a /// newtyped value, to be more efficiently serialized than a tuple struct with multiple items. /// By default it just serializes the value as a tuple struct sequence. #[inline] - fn visit_newtype_struct(&mut self, + fn serialize_newtype_struct(&mut self, name: &'static str, value: T) -> Result<(), Self::Error> where T: Serialize, { - self.visit_tuple_struct(name, Some(value)) + self.serialize_tuple_struct(name, Some(value)) } - /// The `visit_newtype_variant` allows a variant with a single item to be more efficiently + /// Allows a variant with a single item to be more efficiently /// serialized than a variant with multiple items. By default it just serializes the value as a /// tuple variant sequence. #[inline] - fn visit_newtype_variant(&mut self, + fn serialize_newtype_variant(&mut self, name: &'static str, variant_index: usize, variant: &'static str, value: T) -> Result<(), Self::Error> where T: Serialize, { - self.visit_tuple_variant( + self.serialize_tuple_variant( name, variant_index, variant, Some(value)) } - /// Serializes a `None` value. - fn visit_none(&mut self) -> Result<(), Self::Error>; + /// Serializes a `None` value..serialize + fn serialize_none(&mut self) -> Result<(), Self::Error>; /// Serializes a `Some(...)` value. - fn visit_some(&mut self, value: V) -> Result<(), Self::Error> + fn serialize_some(&mut self, value: V) -> Result<(), Self::Error> where V: Serialize; /// Serializes a sequence. /// /// Callees of this method need to construct a `SeqVisitor`, which iterates through each item /// in the sequence. - fn visit_seq(&mut self, visitor: V) -> Result<(), Self::Error> + fn serialize_seq(&mut self, visitor: V) -> Result<(), Self::Error> where V: SeqVisitor; /// Serializes a sequence element. - fn visit_seq_elt(&mut self, value: T) -> Result<(), Self::Error> + fn serialize_seq_elt(&mut self, value: T) -> Result<(), Self::Error> where T: Serialize; /// Serializes a tuple. /// /// By default this serializes a tuple as a sequence. #[inline] - fn visit_tuple(&mut self, visitor: V) -> Result<(), Self::Error> + fn serialize_tuple(&mut self, visitor: V) -> Result<(), Self::Error> where V: SeqVisitor, { - self.visit_seq(visitor) + self.serialize_seq(visitor) } /// Serializes a tuple element. /// /// By default, tuples are serialized as a sequence. #[inline] - fn visit_tuple_elt(&mut self, value: T) -> Result<(), Self::Error> + fn serialize_tuple_elt(&mut self, value: T) -> Result<(), Self::Error> where T: Serialize { - self.visit_seq_elt(value) + self.serialize_seq_elt(value) } /// Serializes a tuple struct. /// /// By default, tuple structs are serialized as a tuple. #[inline] - fn visit_tuple_struct(&mut self, + fn serialize_tuple_struct(&mut self, _name: &'static str, visitor: V) -> Result<(), Self::Error> where V: SeqVisitor, { - self.visit_tuple(visitor) + self.serialize_tuple(visitor) } /// Serializes a tuple struct element. /// /// By default, tuple struct elements are serialized as a tuple element. #[inline] - fn visit_tuple_struct_elt(&mut self, value: T) -> Result<(), Self::Error> + fn serialize_tuple_struct_elt(&mut self, value: T) -> Result<(), Self::Error> where T: Serialize { - self.visit_tuple_elt(value) + self.serialize_tuple_elt(value) } /// Serializes a tuple variant. /// /// By default, tuple variants are serialized as a tuple struct. #[inline] - fn visit_tuple_variant(&mut self, + fn serialize_tuple_variant(&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) + self.serialize_tuple_struct(variant, visitor) } /// Serializes a tuple element. /// /// By default, tuples are serialized as a sequence. #[inline] - fn visit_tuple_variant_elt(&mut self, value: T) -> Result<(), Self::Error> + fn serialize_tuple_variant_elt(&mut self, value: T) -> Result<(), Self::Error> where T: Serialize { - self.visit_tuple_struct_elt(value) + self.serialize_tuple_struct_elt(value) } /// Serializes a map. /// /// Callees of this method need to construct a `MapVisitor`, which iterates through each item /// in the map. - fn visit_map(&mut self, visitor: V) -> Result<(), Self::Error> + fn serialize_map(&mut self, visitor: V) -> Result<(), Self::Error> where V: MapVisitor; /// Serializes a map element (key-value pair). - fn visit_map_elt(&mut self, key: K, value: V) -> Result<(), Self::Error> + fn serialize_map_elt(&mut self, key: K, value: V) -> Result<(), Self::Error> where K: Serialize, V: Serialize; @@ -266,50 +266,50 @@ pub trait Serializer { /// /// By default, structs are serialized as a map with the field name as the key. #[inline] - fn visit_struct(&mut self, + fn serialize_struct(&mut self, _name: &'static str, visitor: V) -> Result<(), Self::Error> where V: MapVisitor, { - self.visit_map(visitor) + self.serialize_map(visitor) } /// Serializes an element of a struct. /// /// By default, struct elements are serialized as a map element with the field name as the key. #[inline] - fn visit_struct_elt(&mut self, + fn serialize_struct_elt(&mut self, key: &'static str, value: V) -> Result<(), Self::Error> where V: Serialize, { - self.visit_map_elt(key, value) + self.serialize_map_elt(key, value) } /// Serializes a struct variant. /// /// By default, struct variants are serialized as a struct. #[inline] - fn visit_struct_variant(&mut self, + fn serialize_struct_variant(&mut self, _name: &'static str, _variant_index: usize, variant: &'static str, visitor: V) -> Result<(), Self::Error> where V: MapVisitor, { - self.visit_struct(variant, visitor) + self.serialize_struct(variant, visitor) } /// Serializes an element of a struct variant. /// /// By default, struct variant elements are serialized as a struct element. #[inline] - fn visit_struct_variant_elt(&mut self, + fn serialize_struct_variant_elt(&mut self, key: &'static str, value: V) -> Result<(), Self::Error> where V: Serialize, { - self.visit_struct_elt(key, value) + self.serialize_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 4268326c..08cd342c 100644 --- a/serde_codegen/src/de.rs +++ b/serde_codegen/src/de.rs @@ -277,7 +277,7 @@ fn deserialize_unit_struct( } } - deserializer.visit_unit_struct($type_name, __Visitor) + deserializer.deserialize_unit_struct($type_name, __Visitor) }) } @@ -329,7 +329,7 @@ fn deserialize_newtype_struct( } } - deserializer.visit_newtype_struct($type_name, $visitor_expr) + deserializer.deserialize_newtype_struct($type_name, $visitor_expr) }) } @@ -374,7 +374,7 @@ fn deserialize_tuple_struct( } } - deserializer.visit_tuple_struct($type_name, $fields, $visitor_expr) + deserializer.deserialize_tuple_struct($type_name, $fields, $visitor_expr) }) } @@ -517,7 +517,7 @@ fn deserialize_struct( $fields_stmt - deserializer.visit_struct($type_name, FIELDS, $visitor_expr) + deserializer.deserialize_struct($type_name, FIELDS, $visitor_expr) }) } @@ -608,7 +608,7 @@ fn deserialize_item_enum( $variants_stmt - deserializer.visit_enum($type_name, VARIANTS, $visitor_expr) + deserializer.deserialize_enum($type_name, VARIANTS, $visitor_expr) }) } @@ -910,7 +910,7 @@ fn deserialize_field_visitor( } } - deserializer.visit(__FieldVisitor::{ phantom: PhantomData }) + deserializer.deserialize(__FieldVisitor::{ phantom: PhantomData }) } } ).unwrap(); diff --git a/serde_codegen/src/ser.rs b/serde_codegen/src/ser.rs index 4f0d6845..5bb54191 100644 --- a/serde_codegen/src/ser.rs +++ b/serde_codegen/src/ser.rs @@ -166,7 +166,7 @@ fn serialize_unit_struct( ) -> P { let type_name = builder.expr().str(type_ident); - quote_expr!(cx, serializer.visit_unit_struct($type_name)) + quote_expr!(cx, serializer.serialize_unit_struct($type_name)) } fn serialize_newtype_struct( @@ -176,7 +176,7 @@ fn serialize_newtype_struct( ) -> P { let type_name = builder.expr().str(type_ident); - quote_expr!(cx, serializer.visit_newtype_struct($type_name, &self.0)) + quote_expr!(cx, serializer.serialize_newtype_struct($type_name, &self.0)) } fn serialize_tuple_struct( @@ -204,7 +204,7 @@ fn serialize_tuple_struct( quote_expr!(cx, { $visitor_struct $visitor_impl - serializer.visit_tuple_struct($type_name, Visitor { + serializer.serialize_tuple_struct($type_name, Visitor { value: self, state: 0, _structure_ty: ::std::marker::PhantomData::<&$ty>, @@ -241,7 +241,7 @@ fn serialize_struct( quote_expr!(cx, { $visitor_struct $visitor_impl - serializer.visit_struct($type_name, Visitor { + serializer.serialize_struct($type_name, Visitor { value: self, state: 0, _structure_ty: ::std::marker::PhantomData::<&$ty>, @@ -300,7 +300,7 @@ fn serialize_variant( quote_arm!(cx, $pat => { - ::serde::ser::Serializer::visit_unit_variant( + ::serde::ser::Serializer::serialize_unit_variant( serializer, $type_name, $variant_index, @@ -318,7 +318,7 @@ fn serialize_variant( .build(); quote_arm!(cx, $pat => { - ::serde::ser::Serializer::visit_newtype_variant( + ::serde::ser::Serializer::serialize_newtype_variant( serializer, $type_name, $variant_index, @@ -437,7 +437,7 @@ fn serialize_tuple_variant( quote_expr!(cx, { $visitor_struct $visitor_impl - serializer.visit_tuple_variant($type_name, $variant_index, $variant_name, Visitor { + serializer.serialize_tuple_variant($type_name, $variant_index, $variant_name, Visitor { value: $value_expr, state: 0, _structure_ty: ::std::marker::PhantomData::<&$structure_ty>, @@ -492,7 +492,7 @@ fn serialize_struct_variant( quote_expr!(cx, { $visitor_struct $visitor_impl - serializer.visit_struct_variant($type_name, $variant_index, $variant_name, Visitor { + serializer.serialize_struct_variant($type_name, $variant_index, $variant_name, Visitor { value: $value_expr, state: 0, _structure_ty: ::std::marker::PhantomData::<&$structure_ty>, @@ -517,7 +517,7 @@ fn serialize_tuple_struct_visitor( quote_arm!(cx, $i => { self.state += 1; - let v = try!(serializer.visit_tuple_struct_elt(&$expr)); + let v = try!(serializer.serialize_tuple_struct_elt(&$expr)); Ok(Some(v)) } ) @@ -605,7 +605,7 @@ fn serialize_struct_visitor( return Ok( Some( try!( - serializer.visit_struct_elt( + serializer.serialize_struct_elt( $key_expr, $value_expr, )