Merge pull request #170 from oli-obk/master

fix(#151): renaming Deserializer::visit_* to Deserializer::deserialize_*
This commit is contained in:
Erick Tryzelaar 2015-10-31 16:56:06 -07:00
commit 4bdabea639
14 changed files with 311 additions and 311 deletions

View File

@ -54,7 +54,7 @@ impl<'a> ser::Serialize for Bytes<'a> {
fn serialize<S>(&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<S>(&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<D>(deserializer: &mut D) -> Result<ByteBuf, D::Error>
where D: de::Deserializer
{
deserializer.visit_bytes(ByteBufVisitor)
deserializer.deserialize_bytes(ByteBufVisitor)
}
}

View File

@ -64,7 +64,7 @@ impl Deserialize for () {
fn deserialize<D>(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<D>(deserializer: &mut D) -> Result<bool, D::Error>
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<D>(deserializer: &mut D) -> Result<char, D::Error>
where D: Deserializer,
{
deserializer.visit_char(CharVisitor)
deserializer.deserialize_char(CharVisitor)
}
}
@ -266,7 +266,7 @@ impl Deserialize for String {
fn deserialize<D>(deserializer: &mut D) -> Result<String, D::Error>
where D: Deserializer,
{
deserializer.visit_string(StringVisitor)
deserializer.deserialize_string(StringVisitor)
}
}
@ -300,7 +300,7 @@ impl<T> Deserialize for Option<T> where T: Deserialize {
fn deserialize<D>(deserializer: &mut D) -> Result<Option<T>, 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<D>(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<T> Deserialize for [T; 0]
fn deserialize<D>(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<D>(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<D>(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<D>(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<D>(deserializer: &mut D) -> Result<path::PathBuf, D::Error>
where D: Deserializer,
{
deserializer.visit(PathBufVisitor)
deserializer.deserialize(PathBufVisitor)
}
}
@ -862,7 +862,7 @@ impl<T, E> Deserialize for Result<T, E> where T: Deserialize, E: Deserialize {
}
}
deserializer.visit(FieldVisitor)
deserializer.deserialize(FieldVisitor)
}
}
@ -892,6 +892,6 @@ impl<T, E> Deserialize for Result<T, E> 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))
}
}

View File

@ -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<V>(&mut self, visitor: V) -> Result<V::Value, Self::Error>
fn deserialize<V>(&mut self, visitor: V) -> Result<V::Value, Self::Error>
where V: Visitor;
/// This method hints that the `Deserialize` type is expecting a `bool` value.
#[inline]
fn visit_bool<V>(&mut self, visitor: V) -> Result<V::Value, Self::Error>
fn deserialize_bool<V>(&mut self, visitor: V) -> Result<V::Value, Self::Error>
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<V>(&mut self, visitor: V) -> Result<V::Value, Self::Error>
fn deserialize_usize<V>(&mut self, visitor: V) -> Result<V::Value, Self::Error>
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<V>(&mut self, visitor: V) -> Result<V::Value, Self::Error>
fn deserialize_u8<V>(&mut self, visitor: V) -> Result<V::Value, Self::Error>
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<V>(&mut self, visitor: V) -> Result<V::Value, Self::Error>
fn deserialize_u16<V>(&mut self, visitor: V) -> Result<V::Value, Self::Error>
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<V>(&mut self, visitor: V) -> Result<V::Value, Self::Error>
fn deserialize_u32<V>(&mut self, visitor: V) -> Result<V::Value, Self::Error>
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<V>(&mut self, visitor: V) -> Result<V::Value, Self::Error>
fn deserialize_u64<V>(&mut self, visitor: V) -> Result<V::Value, Self::Error>
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<V>(&mut self, visitor: V) -> Result<V::Value, Self::Error>
fn deserialize_isize<V>(&mut self, visitor: V) -> Result<V::Value, Self::Error>
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<V>(&mut self, visitor: V) -> Result<V::Value, Self::Error>
fn deserialize_i8<V>(&mut self, visitor: V) -> Result<V::Value, Self::Error>
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<V>(&mut self, visitor: V) -> Result<V::Value, Self::Error>
fn deserialize_i16<V>(&mut self, visitor: V) -> Result<V::Value, Self::Error>
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<V>(&mut self, visitor: V) -> Result<V::Value, Self::Error>
fn deserialize_i32<V>(&mut self, visitor: V) -> Result<V::Value, Self::Error>
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<V>(&mut self, visitor: V) -> Result<V::Value, Self::Error>
fn deserialize_i64<V>(&mut self, visitor: V) -> Result<V::Value, Self::Error>
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<V>(&mut self, visitor: V) -> Result<V::Value, Self::Error>
fn deserialize_f32<V>(&mut self, visitor: V) -> Result<V::Value, Self::Error>
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<V>(&mut self, visitor: V) -> Result<V::Value, Self::Error>
fn deserialize_f64<V>(&mut self, visitor: V) -> Result<V::Value, Self::Error>
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<V>(&mut self, visitor: V) -> Result<V::Value, Self::Error>
fn deserialize_char<V>(&mut self, visitor: V) -> Result<V::Value, Self::Error>
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<V>(&mut self, visitor: V) -> Result<V::Value, Self::Error>
fn deserialize_str<V>(&mut self, visitor: V) -> Result<V::Value, Self::Error>
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<V>(&mut self, visitor: V) -> Result<V::Value, Self::Error>
fn deserialize_string<V>(&mut self, visitor: V) -> Result<V::Value, Self::Error>
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<V>(&mut self, visitor: V) -> Result<V::Value, Self::Error>
fn deserialize_unit<V>(&mut self, visitor: V) -> Result<V::Value, Self::Error>
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<V>(&mut self, visitor: V) -> Result<V::Value, Self::Error>
fn deserialize_option<V>(&mut self, visitor: V) -> Result<V::Value, Self::Error>
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<V>(&mut self, visitor: V) -> Result<V::Value, Self::Error>
fn deserialize_seq<V>(&mut self, visitor: V) -> Result<V::Value, Self::Error>
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<V>(&mut self, visitor: V) -> Result<V::Value, Self::Error>
fn deserialize_map<V>(&mut self, visitor: V) -> Result<V::Value, Self::Error>
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<V>(&mut self,
fn deserialize_unit_struct<V>(&mut self,
_name: &'static str,
visitor: V) -> Result<V::Value, Self::Error>
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<V>(&mut self,
fn deserialize_newtype_struct<V>(&mut self,
name: &'static str,
visitor: V) -> Result<V::Value, Self::Error>
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<V>(&mut self,
fn deserialize_tuple_struct<V>(&mut self,
_name: &'static str,
len: usize,
visitor: V) -> Result<V::Value, Self::Error>
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<V>(&mut self,
fn deserialize_struct<V>(&mut self,
_name: &'static str,
_fields: &'static [&'static str],
visitor: V) -> Result<V::Value, Self::Error>
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<V>(&mut self, _len: usize, visitor: V) -> Result<V::Value, Self::Error>
fn deserialize_tuple<V>(&mut self, _len: usize, visitor: V) -> Result<V::Value, Self::Error>
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<V>(&mut self,
fn deserialize_enum<V>(&mut self,
_enum: &'static str,
_variants: &'static [&'static str],
_visitor: V) -> Result<V::Value, Self::Error>
@ -393,10 +393,10 @@ pub trait Deserializer {
/// deserializers that provide a custom byte vector serialization to properly deserialize the
/// type.
#[inline]
fn visit_bytes<V>(&mut self, visitor: V) -> Result<V::Value, Self::Error>
fn deserialize_bytes<V>(&mut self, visitor: V) -> Result<V::Value, Self::Error>
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<V>(&mut self, field: &'static str) -> Result<V, Self::Error>
where V: Deserialize,
{

View File

@ -81,13 +81,13 @@ impl<E> de::Deserializer for UnitDeserializer<E>
{
type Error = E;
fn visit<V>(&mut self, mut visitor: V) -> Result<V::Value, Self::Error>
fn deserialize<V>(&mut self, mut visitor: V) -> Result<V::Value, Self::Error>
where V: de::Visitor,
{
visitor.visit_unit()
}
fn visit_option<V>(&mut self, mut visitor: V) -> Result<V::Value, Self::Error>
fn deserialize_option<V>(&mut self, mut visitor: V) -> Result<V::Value, Self::Error>
where V: de::Visitor,
{
visitor.visit_none()
@ -116,7 +116,7 @@ macro_rules! primitive_deserializer {
{
type Error = E;
fn visit<V>(&mut self, mut visitor: V) -> Result<V::Value, Self::Error>
fn deserialize<V>(&mut self, mut visitor: V) -> Result<V::Value, Self::Error>
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<V>(&mut self, mut visitor: V) -> Result<V::Value, Self::Error>
fn deserialize<V>(&mut self, mut visitor: V) -> Result<V::Value, Self::Error>
where V: de::Visitor,
{
match self.0.take() {
@ -172,7 +172,7 @@ impl<'a, E> de::Deserializer for StrDeserializer<'a, E>
}
}
fn visit_enum<V>(&mut self,
fn deserialize_enum<V>(&mut self,
_name: &str,
_variants: &'static [&'static str],
mut visitor: V) -> Result<V::Value, Self::Error>
@ -218,7 +218,7 @@ impl<E> de::Deserializer for StringDeserializer<E>
{
type Error = E;
fn visit<V>(&mut self, mut visitor: V) -> Result<V::Value, Self::Error>
fn deserialize<V>(&mut self, mut visitor: V) -> Result<V::Value, Self::Error>
where V: de::Visitor,
{
match self.0.take() {
@ -227,7 +227,7 @@ impl<E> de::Deserializer for StringDeserializer<E>
}
}
fn visit_enum<V>(&mut self,
fn deserialize_enum<V>(&mut self,
_name: &str,
_variants: &'static [&'static str],
mut visitor: V) -> Result<V::Value, Self::Error>
@ -282,7 +282,7 @@ impl<I, T, E> de::Deserializer for SeqDeserializer<I, E>
{
type Error = E;
fn visit<V>(&mut self, mut visitor: V) -> Result<V::Value, Self::Error>
fn deserialize<V>(&mut self, mut visitor: V) -> Result<V::Value, Self::Error>
where V: de::Visitor,
{
visitor.visit_seq(self)
@ -387,7 +387,7 @@ impl<V_, E> de::Deserializer for SeqVisitorDeserializer<V_, E>
{
type Error = E;
fn visit<V: de::Visitor>(&mut self, mut visitor: V) -> Result<V::Value, Self::Error> {
fn deserialize<V: de::Visitor>(&mut self, mut visitor: V) -> Result<V::Value, Self::Error> {
visitor.visit_seq(&mut self.visitor)
}
}
@ -432,7 +432,7 @@ impl<I, K, V, E> de::Deserializer for MapDeserializer<I, K, V, E>
{
type Error = E;
fn visit<V_>(&mut self, mut visitor: V_) -> Result<V_::Value, Self::Error>
fn deserialize<V_>(&mut self, mut visitor: V_) -> Result<V_::Value, Self::Error>
where V_: de::Visitor,
{
visitor.visit_map(self)
@ -541,7 +541,7 @@ impl<V_, E> de::Deserializer for MapVisitorDeserializer<V_, E>
{
type Error = E;
fn visit<V: de::Visitor>(&mut self, mut visitor: V) -> Result<V::Value, Self::Error> {
fn deserialize<V: de::Visitor>(&mut self, mut visitor: V) -> Result<V::Value, Self::Error> {
visitor.visit_map(&mut self.visitor)
}
}
@ -566,7 +566,7 @@ impl<'a, E> de::Deserializer for BytesDeserializer<'a, E>
{
type Error = E;
fn visit<V>(&mut self, mut visitor: V) -> Result<V::Value, Self::Error>
fn deserialize<V>(&mut self, mut visitor: V) -> Result<V::Value, Self::Error>
where V: de::Visitor,
{
match self.0.take() {
@ -597,7 +597,7 @@ impl<E> de::Deserializer for ByteBufDeserializer<E>
{
type Error = E;
fn visit<V>(&mut self, mut visitor: V) -> Result<V::Value, Self::Error>
fn deserialize<V>(&mut self, mut visitor: V) -> Result<V::Value, Self::Error>
where V: de::Visitor,
{
match self.0.take() {

View File

@ -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<S>(&self, serializer: &mut S) -> Result<(), S::Error>
where S: Serializer,
{
serializer.visit_str(self)
serializer.serialize_str(self)
}
}
@ -91,8 +91,8 @@ impl<T> Serialize for Option<T> 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<T> SeqVisitor for Option<T> 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<T> SeqVisitor for Option<T> where T: Serialize {
/// fn serialize<S>(&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<T, Iter> SeqVisitor for SeqIteratorVisitor<Iter>
{
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<T> Serialize for [T]
fn serialize<S>(&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<S>(&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<T> Serialize for BinaryHeap<T>
fn serialize<S>(&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<T> Serialize for BTreeSet<T>
fn serialize<S>(&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<T> Serialize for EnumSet<T>
fn serialize<S>(&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<T> Serialize for HashSet<T>
fn serialize<S>(&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<T> Serialize for LinkedList<T>
fn serialize<S>(&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<A> Serialize for ops::Range<A>
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<T> Serialize for VecDeque<T> where T: Serialize {
fn serialize<S>(&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<S>(&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<S: Serializer>(&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<S>(&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<K, V, I> MapVisitor for MapIteratorVisitor<I>
{
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<K, V> Serialize for BTreeMap<K, V>
fn serialize<S>(&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<K, V> Serialize for HashMap<K, V>
fn serialize<S>(&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<T, E> Serialize for Result<T, E> where T: Serialize, E: Serialize {
fn serialize<S>(&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)
}
}
}

View File

@ -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<T>(&mut self,
fn serialize_newtype_struct<T>(&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<T>(&mut self,
fn serialize_newtype_variant<T>(&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<V>(&mut self, value: V) -> Result<(), Self::Error>
fn serialize_some<V>(&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<V>(&mut self, visitor: V) -> Result<(), Self::Error>
fn serialize_seq<V>(&mut self, visitor: V) -> Result<(), Self::Error>
where V: SeqVisitor;
/// Serializes a sequence element.
fn visit_seq_elt<T>(&mut self, value: T) -> Result<(), Self::Error>
fn serialize_seq_elt<T>(&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<V>(&mut self, visitor: V) -> Result<(), Self::Error>
fn serialize_tuple<V>(&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<T>(&mut self, value: T) -> Result<(), Self::Error>
fn serialize_tuple_elt<T>(&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<V>(&mut self,
fn serialize_tuple_struct<V>(&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<T>(&mut self, value: T) -> Result<(), Self::Error>
fn serialize_tuple_struct_elt<T>(&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<V>(&mut self,
fn serialize_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)
self.serialize_tuple_struct(variant, visitor)
}
/// Serializes a tuple element.
///
/// By default, tuples are serialized as a sequence.
#[inline]
fn visit_tuple_variant_elt<T>(&mut self, value: T) -> Result<(), Self::Error>
fn serialize_tuple_variant_elt<T>(&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<V>(&mut self, visitor: V) -> Result<(), Self::Error>
fn serialize_map<V>(&mut self, visitor: V) -> Result<(), Self::Error>
where V: MapVisitor;
/// Serializes a map element (key-value pair).
fn visit_map_elt<K, V>(&mut self, key: K, value: V) -> Result<(), Self::Error>
fn serialize_map_elt<K, V>(&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<V>(&mut self,
fn serialize_struct<V>(&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<V>(&mut self,
fn serialize_struct_elt<V>(&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<V>(&mut self,
fn serialize_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)
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<V>(&mut self,
fn serialize_struct_variant_elt<V>(&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.

View File

@ -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::<D>{ phantom: PhantomData })
deserializer.deserialize(__FieldVisitor::<D>{ phantom: PhantomData })
}
}
).unwrap();

View File

@ -166,7 +166,7 @@ fn serialize_unit_struct(
) -> P<ast::Expr> {
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<ast::Expr> {
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<I>(
return Ok(
Some(
try!(
serializer.visit_struct_elt(
serializer.serialize_struct_elt(
$key_expr,
$value_expr,
)

View File

@ -262,7 +262,7 @@ mod deserializer {
type Error = Error;
#[inline]
fn visit<V>(&mut self, mut visitor: V) -> Result<V::Value, Error>
fn deserialize<V>(&mut self, mut visitor: V) -> Result<V::Value, Error>
where V: de::Visitor,
{
match self.stack.pop() {
@ -288,7 +288,7 @@ mod deserializer {
}
#[inline]
fn visit_enum<V>(&mut self,
fn deserialize_enum<V>(&mut self,
_name: &str,
_variants: &[&str],
mut visitor: V) -> Result<V::Value, Error>

View File

@ -252,7 +252,7 @@ mod deserializer {
impl de::Deserializer for IsizeDeserializer {
type Error = Error;
fn visit<V>(&mut self, mut visitor: V) -> Result<V::Value, Error>
fn deserialize<V>(&mut self, mut visitor: V) -> Result<V::Value, Error>
where V: de::Visitor,
{
match self.stack.pop() {

View File

@ -356,7 +356,7 @@ mod deserializer {
impl de::Deserializer for OuterDeserializer {
type Error = Error;
fn visit<V>(&mut self, mut visitor: V) -> Result<V::Value, Error>
fn deserialize<V>(&mut self, mut visitor: V) -> Result<V::Value, Error>
where V: de::Visitor,
{
match self.stack.pop() {
@ -398,7 +398,7 @@ mod deserializer {
}
}
fn visit_struct<V>(&mut self,
fn deserialize_struct<V>(&mut self,
name: &str,
_fields: &'static [&'static str],
mut visitor: V) -> Result<V::Value, Error>

View File

@ -378,7 +378,7 @@ mod deserializer {
type Error = Error;
#[inline]
fn visit<V>(&mut self, mut visitor: V) -> Result<V::Value, Error>
fn deserialize<V>(&mut self, mut visitor: V) -> Result<V::Value, Error>
where V: de::Visitor,
{
match self.state {
@ -437,7 +437,7 @@ mod deserializer {
type Error = Error;
#[inline]
fn visit<V>(&mut self, mut visitor: V) -> Result<V::Value, Error>
fn deserialize<V>(&mut self, mut visitor: V) -> Result<V::Value, Error>
where V: de::Visitor,
{
match self.state {

View File

@ -34,74 +34,74 @@ impl BytesSerializer {
impl serde::Serializer for BytesSerializer {
type Error = Error;
fn visit_unit(&mut self) -> Result<(), Error> {
fn serialize_unit(&mut self) -> Result<(), Error> {
Err(Error)
}
fn visit_bool(&mut self, _v: bool) -> Result<(), Error> {
fn serialize_bool(&mut self, _v: bool) -> Result<(), Error> {
Err(Error)
}
fn visit_i64(&mut self, _v: i64) -> Result<(), Error> {
fn serialize_i64(&mut self, _v: i64) -> Result<(), Error> {
Err(Error)
}
fn visit_u64(&mut self, _v: u64) -> Result<(), Error> {
fn serialize_u64(&mut self, _v: u64) -> Result<(), Error> {
Err(Error)
}
fn visit_f32(&mut self, _v: f32) -> Result<(), Error> {
fn serialize_f32(&mut self, _v: f32) -> Result<(), Error> {
Err(Error)
}
fn visit_f64(&mut self, _v: f64) -> Result<(), Error> {
fn serialize_f64(&mut self, _v: f64) -> Result<(), Error> {
Err(Error)
}
fn visit_char(&mut self, _v: char) -> Result<(), Error> {
fn serialize_char(&mut self, _v: char) -> Result<(), Error> {
Err(Error)
}
fn visit_str(&mut self, _v: &str) -> Result<(), Error> {
fn serialize_str(&mut self, _v: &str) -> Result<(), Error> {
Err(Error)
}
fn visit_none(&mut self) -> Result<(), Error> {
fn serialize_none(&mut self) -> Result<(), Error> {
Err(Error)
}
fn visit_some<V>(&mut self, _value: V) -> Result<(), Error>
fn serialize_some<V>(&mut self, _value: V) -> Result<(), Error>
where V: serde::Serialize,
{
Err(Error)
}
fn visit_seq<V>(&mut self, _visitor: V) -> Result<(), Error>
fn serialize_seq<V>(&mut self, _visitor: V) -> Result<(), Error>
where V: serde::ser::SeqVisitor,
{
Err(Error)
}
fn visit_seq_elt<T>(&mut self, _value: T) -> Result<(), Error>
fn serialize_seq_elt<T>(&mut self, _value: T) -> Result<(), Error>
where T: serde::Serialize
{
Err(Error)
}
fn visit_map<V>(&mut self, _visitor: V) -> Result<(), Error>
fn serialize_map<V>(&mut self, _visitor: V) -> Result<(), Error>
where V: serde::ser::MapVisitor,
{
Err(Error)
}
fn visit_map_elt<K, V>(&mut self, _key: K, _value: V) -> Result<(), Error>
fn serialize_map_elt<K, V>(&mut self, _key: K, _value: V) -> Result<(), Error>
where K: serde::Serialize,
V: serde::Serialize,
{
Err(Error)
}
fn visit_bytes(&mut self, bytes: &[u8]) -> Result<(), Error> {
fn serialize_bytes(&mut self, bytes: &[u8]) -> Result<(), Error> {
assert_eq!(self.bytes, bytes);
Ok(())
}
@ -124,13 +124,13 @@ impl BytesDeserializer {
impl serde::Deserializer for BytesDeserializer {
type Error = Error;
fn visit<V>(&mut self, _visitor: V) -> Result<V::Value, Error>
fn deserialize<V>(&mut self, _visitor: V) -> Result<V::Value, Error>
where V: serde::de::Visitor,
{
Err(Error)
}
fn visit_bytes<V>(&mut self, mut visitor: V) -> Result<V::Value, Error>
fn deserialize_bytes<V>(&mut self, mut visitor: V) -> Result<V::Value, Error>
where V: serde::de::Visitor,
{
visitor.visit_byte_buf(self.bytes.take().unwrap())

View File

@ -89,12 +89,12 @@ impl<'a, I> ser::Serializer for Serializer<I>
{
type Error = ();
fn visit_unit(&mut self) -> Result<(), ()> {
fn serialize_unit(&mut self) -> Result<(), ()> {
assert_eq!(self.tokens.next(), Some(&Token::Unit));
Ok(())
}
fn visit_newtype_variant<T>(&mut self,
fn serialize_newtype_variant<T>(&mut self,
name: &str,
_variant_index: usize,
variant: &str,
@ -105,12 +105,12 @@ impl<'a, I> ser::Serializer for Serializer<I>
value.serialize(self)
}
fn visit_unit_struct(&mut self, name: &str) -> Result<(), ()> {
fn serialize_unit_struct(&mut self, name: &str) -> Result<(), ()> {
assert_eq!(self.tokens.next(), Some(&Token::UnitStruct(name)));
Ok(())
}
fn visit_unit_variant(&mut self,
fn serialize_unit_variant(&mut self,
name: &str,
_variant_index: usize,
variant: &str) -> Result<(), ()> {
@ -119,87 +119,87 @@ impl<'a, I> ser::Serializer for Serializer<I>
Ok(())
}
fn visit_bool(&mut self, v: bool) -> Result<(), ()> {
fn serialize_bool(&mut self, v: bool) -> Result<(), ()> {
assert_eq!(self.tokens.next(), Some(&Token::Bool(v)));
Ok(())
}
fn visit_isize(&mut self, v: isize) -> Result<(), ()> {
fn serialize_isize(&mut self, v: isize) -> Result<(), ()> {
assert_eq!(self.tokens.next(), Some(&Token::Isize(v)));
Ok(())
}
fn visit_i8(&mut self, v: i8) -> Result<(), ()> {
fn serialize_i8(&mut self, v: i8) -> Result<(), ()> {
assert_eq!(self.tokens.next(), Some(&Token::I8(v)));
Ok(())
}
fn visit_i16(&mut self, v: i16) -> Result<(), ()> {
fn serialize_i16(&mut self, v: i16) -> Result<(), ()> {
assert_eq!(self.tokens.next(), Some(&Token::I16(v)));
Ok(())
}
fn visit_i32(&mut self, v: i32) -> Result<(), ()> {
fn serialize_i32(&mut self, v: i32) -> Result<(), ()> {
assert_eq!(self.tokens.next(), Some(&Token::I32(v)));
Ok(())
}
fn visit_i64(&mut self, v: i64) -> Result<(), ()> {
fn serialize_i64(&mut self, v: i64) -> Result<(), ()> {
assert_eq!(self.tokens.next(), Some(&Token::I64(v)));
Ok(())
}
fn visit_usize(&mut self, v: usize) -> Result<(), ()> {
fn serialize_usize(&mut self, v: usize) -> Result<(), ()> {
assert_eq!(self.tokens.next(), Some(&Token::Usize(v)));
Ok(())
}
fn visit_u8(&mut self, v: u8) -> Result<(), ()> {
fn serialize_u8(&mut self, v: u8) -> Result<(), ()> {
assert_eq!(self.tokens.next(), Some(&Token::U8(v)));
Ok(())
}
fn visit_u16(&mut self, v: u16) -> Result<(), ()> {
fn serialize_u16(&mut self, v: u16) -> Result<(), ()> {
assert_eq!(self.tokens.next(), Some(&Token::U16(v)));
Ok(())
}
fn visit_u32(&mut self, v: u32) -> Result<(), ()> {
fn serialize_u32(&mut self, v: u32) -> Result<(), ()> {
assert_eq!(self.tokens.next(), Some(&Token::U32(v)));
Ok(())
}
fn visit_u64(&mut self, v: u64) -> Result<(), ()> {
fn serialize_u64(&mut self, v: u64) -> Result<(), ()> {
assert_eq!(self.tokens.next(), Some(&Token::U64(v)));
Ok(())
}
fn visit_f32(&mut self, v: f32) -> Result<(), ()> {
fn serialize_f32(&mut self, v: f32) -> Result<(), ()> {
assert_eq!(self.tokens.next(), Some(&Token::F32(v)));
Ok(())
}
fn visit_f64(&mut self, v: f64) -> Result<(), ()> {
fn serialize_f64(&mut self, v: f64) -> Result<(), ()> {
assert_eq!(self.tokens.next(), Some(&Token::F64(v)));
Ok(())
}
fn visit_char(&mut self, v: char) -> Result<(), ()> {
fn serialize_char(&mut self, v: char) -> Result<(), ()> {
assert_eq!(self.tokens.next(), Some(&Token::Char(v)));
Ok(())
}
fn visit_str(&mut self, v: &str) -> Result<(), ()> {
fn serialize_str(&mut self, v: &str) -> Result<(), ()> {
assert_eq!(self.tokens.next(), Some(&Token::Str(v)));
Ok(())
}
fn visit_none(&mut self) -> Result<(), ()> {
fn serialize_none(&mut self) -> Result<(), ()> {
assert_eq!(self.tokens.next(), Some(&Token::Option(false)));
Ok(())
}
fn visit_some<V>(&mut self, value: V) -> Result<(), ()>
fn serialize_some<V>(&mut self, value: V) -> Result<(), ()>
where V: ser::Serialize,
{
assert_eq!(self.tokens.next(), Some(&Token::Option(true)));
@ -207,7 +207,7 @@ impl<'a, I> ser::Serializer for Serializer<I>
}
fn visit_seq<V>(&mut self, visitor: V) -> Result<(), ()>
fn serialize_seq<V>(&mut self, visitor: V) -> Result<(), ()>
where V: ser::SeqVisitor
{
let len = visitor.len();
@ -217,7 +217,7 @@ impl<'a, I> ser::Serializer for Serializer<I>
self.visit_sequence(visitor)
}
fn visit_newtype_struct<T>(&mut self,
fn serialize_newtype_struct<T>(&mut self,
name: &'static str,
value: T) -> Result<(), ()>
where T: ser::Serialize,
@ -226,7 +226,7 @@ impl<'a, I> ser::Serializer for Serializer<I>
value.serialize(self)
}
fn visit_tuple_struct<V>(&mut self, name: &str, visitor: V) -> Result<(), ()>
fn serialize_tuple_struct<V>(&mut self, name: &str, visitor: V) -> Result<(), ()>
where V: ser::SeqVisitor
{
let len = visitor.len();
@ -236,7 +236,7 @@ impl<'a, I> ser::Serializer for Serializer<I>
self.visit_sequence(visitor)
}
fn visit_tuple_variant<V>(&mut self,
fn serialize_tuple_variant<V>(&mut self,
name: &str,
_variant_index: usize,
variant: &str,
@ -250,14 +250,14 @@ impl<'a, I> ser::Serializer for Serializer<I>
self.visit_sequence(visitor)
}
fn visit_seq_elt<T>(&mut self, value: T) -> Result<(), ()>
fn serialize_seq_elt<T>(&mut self, value: T) -> Result<(), ()>
where T: ser::Serialize
{
assert_eq!(self.tokens.next(), Some(&Token::SeqSep));
value.serialize(self)
}
fn visit_map<V>(&mut self, visitor: V) -> Result<(), ()>
fn serialize_map<V>(&mut self, visitor: V) -> Result<(), ()>
where V: ser::MapVisitor
{
let len = visitor.len();
@ -267,7 +267,7 @@ impl<'a, I> ser::Serializer for Serializer<I>
self.visit_mapping(visitor)
}
fn visit_struct<V>(&mut self, name: &str, visitor: V) -> Result<(), ()>
fn serialize_struct<V>(&mut self, name: &str, visitor: V) -> Result<(), ()>
where V: ser::MapVisitor
{
let len = visitor.len();
@ -277,7 +277,7 @@ impl<'a, I> ser::Serializer for Serializer<I>
self.visit_mapping(visitor)
}
fn visit_struct_variant<V>(&mut self,
fn serialize_struct_variant<V>(&mut self,
name: &str,
_variant_index: usize,
variant: &str,
@ -291,7 +291,7 @@ impl<'a, I> ser::Serializer for Serializer<I>
self.visit_mapping(visitor)
}
fn visit_map_elt<K, V>(&mut self, key: K, value: V) -> Result<(), ()>
fn serialize_map_elt<K, V>(&mut self, key: K, value: V) -> Result<(), ()>
where K: ser::Serialize,
V: ser::Serialize,
{
@ -376,7 +376,7 @@ impl<I> de::Deserializer for Deserializer<I>
{
type Error = Error;
fn visit<V>(&mut self, mut visitor: V) -> Result<V::Value, Error>
fn deserialize<V>(&mut self, mut visitor: V) -> Result<V::Value, Error>
where V: de::Visitor,
{
println!("visit {:?}", self.tokens.peek());
@ -416,7 +416,7 @@ impl<I> de::Deserializer for Deserializer<I>
/// Hook into `Option` deserializing so we can treat `Unit` as a
/// `None`, or a regular value as `Some(value)`.
fn visit_option<V>(&mut self, mut visitor: V) -> Result<V::Value, Error>
fn deserialize_option<V>(&mut self, mut visitor: V) -> Result<V::Value, Error>
where V: de::Visitor,
{
match self.tokens.peek() {
@ -437,7 +437,7 @@ impl<I> de::Deserializer for Deserializer<I>
}
}
fn visit_enum<V>(&mut self,
fn deserialize_enum<V>(&mut self,
name: &str,
_variants: &'static [&'static str],
mut visitor: V) -> Result<V::Value, Error>
@ -467,7 +467,7 @@ impl<I> de::Deserializer for Deserializer<I>
}
}
fn visit_unit_struct<V>(&mut self, name: &str, mut visitor: V) -> Result<V::Value, Error>
fn deserialize_unit_struct<V>(&mut self, name: &str, mut visitor: V) -> Result<V::Value, Error>
where V: de::Visitor,
{
match self.tokens.peek() {
@ -479,12 +479,12 @@ impl<I> de::Deserializer for Deserializer<I>
Err(Error::InvalidName(n))
}
}
Some(_) => self.visit(visitor),
Some(_) => self.deserialize(visitor),
None => Err(Error::EndOfStreamError),
}
}
fn visit_newtype_struct<V>(&mut self,
fn deserialize_newtype_struct<V>(&mut self,
name: &str,
mut visitor: V) -> Result<V::Value, Error>
where V: de::Visitor,
@ -498,12 +498,12 @@ impl<I> de::Deserializer for Deserializer<I>
Err(Error::InvalidName(n))
}
}
Some(_) => self.visit(visitor),
Some(_) => self.deserialize(visitor),
None => Err(Error::EndOfStreamError),
}
}
fn visit_tuple_struct<V>(&mut self,
fn deserialize_tuple_struct<V>(&mut self,
name: &str,
len: usize,
mut visitor: V) -> Result<V::Value, Error>
@ -530,12 +530,12 @@ impl<I> de::Deserializer for Deserializer<I>
self.tokens.next();
self.visit_seq(Some(len), visitor)
}
Some(_) => self.visit(visitor),
Some(_) => self.deserialize(visitor),
None => Err(Error::EndOfStreamError),
}
}
fn visit_struct<V>(&mut self,
fn deserialize_struct<V>(&mut self,
name: &str,
fields: &'static [&'static str],
visitor: V) -> Result<V::Value, Error>
@ -554,7 +554,7 @@ impl<I> de::Deserializer for Deserializer<I>
self.tokens.next();
self.visit_map(Some(fields.len()), visitor)
}
Some(_) => self.visit(visitor),
Some(_) => self.deserialize(visitor),
None => Err(Error::EndOfStreamError),
}
}