From 2626cf77cb9bd397a26dac1c662e731f03e258be Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Thu, 14 Jul 2016 15:28:51 +0200 Subject: adjust for seq/map ser revamp --- src/encoder/mod.rs | 41 +++++++++++++++++++++++++++++++++++++---- src/encoder/serde.rs | 42 +++++++++++++++++++++++------------------- 2 files changed, 60 insertions(+), 23 deletions(-) (limited to 'src') diff --git a/src/encoder/mod.rs b/src/encoder/mod.rs index 304bac6..0f13b81 100644 --- a/src/encoder/mod.rs +++ b/src/encoder/mod.rs @@ -35,7 +35,7 @@ use {Value, Table}; /// assert_eq!(e.toml.get(&"foo".to_string()), Some(&Value::Integer(4))) /// # } /// ``` -#[derive(Default)] +#[derive(Default, Debug)] pub struct Encoder { /// Output TOML that is emitted. The current version of this encoder forces /// the top-level representation of a structure to be a table. @@ -66,8 +66,9 @@ pub enum Error { Custom(String), } -#[derive(PartialEq)] -enum State { +#[derive(PartialEq, Debug)] +#[doc(hidden)] +pub enum State { Start, NextKey(String), NextArray(Vec), @@ -115,8 +116,16 @@ impl Encoder { fn seq(&mut self, f: F) -> Result<(), Error> where F: FnOnce(&mut Encoder) -> Result<(), Error> { - let old = mem::replace(&mut self.state, State::NextArray(Vec::new())); + let old = try!(self.seq_begin()); try!(f(self)); + self.seq_end(old) + } + + fn seq_begin(&mut self) -> Result { + Ok(mem::replace(&mut self.state, State::NextArray(Vec::new()))) + } + + fn seq_end(&mut self, old: State) -> Result<(), Error> { match mem::replace(&mut self.state, old) { State::NextArray(v) => self.emit_value(Value::Array(v)), _ => unreachable!(), @@ -145,6 +154,30 @@ impl Encoder { } } + fn table_begin(&mut self) -> Result { + match self.state { + State::NextMapKey => Err(Error::InvalidMapKeyLocation), + _ => Ok(mem::replace(self, Encoder::new())) + } + } + + fn table_end(&mut self, mut state: Self) -> Result<(), Error> { + match state.state { + State::NextKey(key) => { + mem::swap(&mut self.toml, &mut state.toml); + self.toml.insert(key, Value::Table(state.toml)); + }, + State::NextArray(mut arr) => { + mem::swap(&mut self.toml, &mut state.toml); + arr.push(Value::Table(state.toml)); + self.state = State::NextArray(arr); + }, + State::Start => {}, + State::NextMapKey => unreachable!(), + } + Ok(()) + } + fn table_key(&mut self, f: F) -> Result<(), Error> where F: FnOnce(&mut Encoder) -> Result<(), Error> { diff --git a/src/encoder/serde.rs b/src/encoder/serde.rs index a782cd2..49a6e2d 100644 --- a/src/encoder/serde.rs +++ b/src/encoder/serde.rs @@ -1,9 +1,11 @@ use serde::ser; use Value; -use super::{Encoder, Error}; +use super::{Encoder, Error, State}; impl ser::Serializer for Encoder { type Error = Error; + type MapState = Self; + type SeqState = State; fn serialize_bool(&mut self, v: bool) -> Result<(), Error> { self.emit_value(Value::Boolean(v)) @@ -34,26 +36,19 @@ impl ser::Serializer for Encoder { { value.serialize(self) } - fn serialize_seq(&mut self, mut visitor: V) -> Result<(), Error> - where V: ser::SeqVisitor - { - self.seq(|me| { - while try!(visitor.visit(me)).is_some() {} - Ok(()) - }) + fn serialize_seq(&mut self, _len: Option) -> Result { + self.seq_begin() } fn serialize_seq_elt(&mut self, value: T) -> Result<(), Error> where T: ser::Serialize { value.serialize(self) } - fn serialize_map(&mut self, mut visitor: V) -> Result<(), Error> - where V: ser::MapVisitor - { - self.table(|me| { - while try!(visitor.visit(me)).is_some() {} - Ok(()) - }) + fn serialize_seq_end(&mut self, _len: Option, state: State) -> Result<(), Error> { + self.seq_end(state) + } + fn serialize_map(&mut self, _len: Option) -> Result { + self.table_begin() } fn serialize_map_elt(&mut self, key: K, value: V) -> Result<(), Error> where K: ser::Serialize, V: ser::Serialize @@ -62,6 +57,9 @@ impl ser::Serializer for Encoder { try!(value.serialize(self)); Ok(()) } + fn serialize_map_end(&mut self, _len: Option, state: Self) -> Result<(), Error> { + self.table_end(state) + } fn serialize_newtype_struct(&mut self, _name: &'static str, value: T) -> Result<(), Self::Error> @@ -93,12 +91,18 @@ impl ser::Serialize for Value { Value::Boolean(b) => e.serialize_bool(b), Value::Datetime(ref s) => e.serialize_str(s), Value::Array(ref a) => { - e.serialize_seq(ser::impls::SeqIteratorVisitor::new(a.iter(), - Some(a.len()))) + let state = try!(e.serialize_seq(Some(a.len()))); + for el in a.iter() { + try!(e.serialize_seq_elt(el)); + } + e.serialize_seq_end(Some(a.len()), state) } Value::Table(ref t) => { - e.serialize_map(ser::impls::MapIteratorVisitor::new(t.iter(), - Some(t.len()))) + let state = try!(e.serialize_map(Some(t.len()))); + for (k, v) in t.iter() { + try!(e.serialize_map_elt(k, v)); + } + e.serialize_map_end(Some(t.len()), state) } } } -- cgit v1.2.3 From f0659e10783cc81ba64095fbac9a53eb5da91716 Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Fri, 15 Jul 2016 16:24:26 +0200 Subject: next iteration --- src/encoder/serde.rs | 128 +++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 118 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/encoder/serde.rs b/src/encoder/serde.rs index 49a6e2d..9c2f602 100644 --- a/src/encoder/serde.rs +++ b/src/encoder/serde.rs @@ -5,7 +5,12 @@ use super::{Encoder, Error, State}; impl ser::Serializer for Encoder { type Error = Error; type MapState = Self; + type StructState = Self; + type StructVariantState = Self; type SeqState = State; + type TupleState = State; + type TupleStructState = State; + type TupleVariantState = State; fn serialize_bool(&mut self, v: bool) -> Result<(), Error> { self.emit_value(Value::Boolean(v)) @@ -16,12 +21,42 @@ impl ser::Serializer for Encoder { fn serialize_u64(&mut self, v: u64) -> Result<(), Error> { self.serialize_i64(v as i64) } + fn serialize_isize(&mut self, v: isize) -> Result<(), Error> { + self.serialize_i64(v as i64) + } + fn serialize_usize(&mut self, v: usize) -> Result<(), Error> { + self.serialize_i64(v as i64) + } + fn serialize_i8(&mut self, v: i8) -> Result<(), Error> { + self.serialize_i64(v as i64) + } + fn serialize_u8(&mut self, v: u8) -> Result<(), Error> { + self.serialize_i64(v as i64) + } + fn serialize_i16(&mut self, v: i16) -> Result<(), Error> { + self.serialize_i64(v as i64) + } + fn serialize_u16(&mut self, v: u16) -> Result<(), Error> { + self.serialize_i64(v as i64) + } + fn serialize_i32(&mut self, v: i32) -> Result<(), Error> { + self.serialize_i64(v as i64) + } + fn serialize_u32(&mut self, v: u32) -> Result<(), Error> { + self.serialize_i64(v as i64) + } + fn serialize_f32(&mut self, v: f32) -> Result<(), Error> { + self.serialize_f64(v as f64) + } fn serialize_f64(&mut self, v: f64) -> Result<(), Error> { self.emit_value(Value::Float(v)) } fn serialize_str(&mut self, value: &str) -> Result<(), Error> { self.emit_value(Value::String(value.to_string())) } + fn serialize_unit_struct(&mut self, _name: &'static str) -> Result<(), Error> { + Ok(()) + } fn serialize_unit(&mut self) -> Result<(), Error> { Ok(()) } @@ -36,30 +71,95 @@ impl ser::Serializer for Encoder { { value.serialize(self) } + fn serialize_bytes(&mut self, v: &[u8]) -> Result<(), Error> { + let mut state = try!(self.serialize_seq(Some(v.len()))); + for c in v { + try!(self.serialize_seq_elt(&mut state, c)); + } + self.serialize_seq_end(state) + } + fn serialize_seq_fixed_size(&mut self, len: usize) -> Result { + self.serialize_seq(Some(len)) + } fn serialize_seq(&mut self, _len: Option) -> Result { self.seq_begin() } - fn serialize_seq_elt(&mut self, value: T) -> Result<(), Error> + fn serialize_seq_elt(&mut self, _state: &mut State, value: T) -> Result<(), Error> where T: ser::Serialize { value.serialize(self) } - fn serialize_seq_end(&mut self, _len: Option, state: State) -> Result<(), Error> { + fn serialize_seq_end(&mut self, state: State) -> Result<(), Error> { self.seq_end(state) } + fn serialize_tuple(&mut self, len: usize) -> Result { + self.serialize_seq(Some(len)) + } + fn serialize_tuple_elt(&mut self, state: &mut State, value: T) -> Result<(), Error> + where T: ser::Serialize + { + self.serialize_seq_elt(state, value) + } + fn serialize_tuple_end(&mut self, state: State) -> Result<(), Error> { + self.serialize_seq_end(state) + } + fn serialize_tuple_struct(&mut self, _name: &'static str, len: usize) -> Result { + self.serialize_seq(Some(len)) + } + fn serialize_tuple_struct_elt(&mut self, state: &mut State, value: T) -> Result<(), Error> + where T: ser::Serialize + { + self.serialize_seq_elt(state, value) + } + fn serialize_tuple_struct_end(&mut self, state: State) -> Result<(), Error> { + self.serialize_seq_end(state) + } + fn serialize_tuple_variant(&mut self, _name: &'static str, _id: usize, _variant: &'static str, len: usize) -> Result { + self.serialize_seq(Some(len)) + } + fn serialize_tuple_variant_elt(&mut self, state: &mut State, value: T) -> Result<(), Error> + where T: ser::Serialize + { + self.serialize_seq_elt(state, value) + } + fn serialize_tuple_variant_end(&mut self, state: State) -> Result<(), Error> { + self.serialize_seq_end(state) + } fn serialize_map(&mut self, _len: Option) -> Result { self.table_begin() } - fn serialize_map_elt(&mut self, key: K, value: V) -> Result<(), Error> + fn serialize_map_elt(&mut self, _state: &mut Encoder, key: K, value: V) -> Result<(), Error> where K: ser::Serialize, V: ser::Serialize { try!(self.table_key(|me| key.serialize(me))); try!(value.serialize(self)); Ok(()) } - fn serialize_map_end(&mut self, _len: Option, state: Self) -> Result<(), Error> { + fn serialize_map_end(&mut self, state: Self) -> Result<(), Error> { self.table_end(state) } + fn serialize_struct(&mut self, _name: &'static str, len: usize) -> Result { + self.serialize_map(Some(len)) + } + fn serialize_struct_elt(&mut self, state: &mut Encoder, key: &'static str, value: V) -> Result<(), Error> + where V: ser::Serialize + { + self.serialize_map_elt(state, key, value) + } + fn serialize_struct_end(&mut self, state: Self) -> Result<(), Error> { + self.serialize_map_end(state) + } + fn serialize_struct_variant(&mut self, _name: &'static str, _id: usize, _variant: &'static str, len: usize) -> Result { + self.serialize_map(Some(len)) + } + fn serialize_struct_variant_elt(&mut self, state: &mut Encoder, key: &'static str, value: V) -> Result<(), Error> + where V: ser::Serialize + { + self.serialize_map_elt(state, key, value) + } + fn serialize_struct_variant_end(&mut self, state: Self) -> Result<(), Error> { + self.serialize_map_end(state) + } fn serialize_newtype_struct(&mut self, _name: &'static str, value: T) -> Result<(), Self::Error> @@ -78,6 +178,14 @@ impl ser::Serializer for Encoder { // Don't serialize the newtype struct variant in a tuple. value.serialize(self) } + fn serialize_unit_variant(&mut self, + _name: &'static str, + _variant_index: usize, + _variant: &'static str, + ) -> Result<(), Self::Error> + { + Ok(()) + } } impl ser::Serialize for Value { @@ -91,18 +199,18 @@ impl ser::Serialize for Value { Value::Boolean(b) => e.serialize_bool(b), Value::Datetime(ref s) => e.serialize_str(s), Value::Array(ref a) => { - let state = try!(e.serialize_seq(Some(a.len()))); + let mut state = try!(e.serialize_seq(Some(a.len()))); for el in a.iter() { - try!(e.serialize_seq_elt(el)); + try!(e.serialize_seq_elt(&mut state, el)); } - e.serialize_seq_end(Some(a.len()), state) + e.serialize_seq_end(state) } Value::Table(ref t) => { - let state = try!(e.serialize_map(Some(t.len()))); + let mut state = try!(e.serialize_map(Some(t.len()))); for (k, v) in t.iter() { - try!(e.serialize_map_elt(k, v)); + try!(e.serialize_map_elt(&mut state, k, v)); } - e.serialize_map_end(Some(t.len()), state) + e.serialize_map_end(state) } } } -- cgit v1.2.3 From d858c1f2d06f977b4d3c26ea82c72eb04bcf5fad Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Thu, 28 Jul 2016 11:01:22 -0700 Subject: Update to serde 0.8.0 --- src/decoder/serde.rs | 124 +++++++++++++++++++++++++++++++++++++++++++++++++++ src/encoder/serde.rs | 22 +++++---- 2 files changed, 138 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/decoder/serde.rs b/src/decoder/serde.rs index 91bc8ac..d854046 100644 --- a/src/decoder/serde.rs +++ b/src/decoder/serde.rs @@ -3,6 +3,43 @@ use Value; use super::{Decoder, DecodeError, DecodeErrorKind}; use std::collections::BTreeMap; +macro_rules! forward_to_deserialize { + ($( + $name:ident ( $( $arg:ident : $ty:ty ),* ); + )*) => { + $( + forward_to_deserialize!{ + func: $name ( $( $arg: $ty ),* ); + } + )* + }; + + (func: deserialize_enum ( $( $arg:ident : $ty:ty ),* );) => { + fn deserialize_enum( + &mut self, + $(_: $ty,)* + _visitor: V, + ) -> ::std::result::Result + where V: ::serde::de::EnumVisitor + { + Err(::serde::de::Error::invalid_type(::serde::de::Type::Enum)) + } + }; + + (func: $name:ident ( $( $arg:ident : $ty:ty ),* );) => { + #[inline] + fn $name( + &mut self, + $(_: $ty,)* + visitor: V, + ) -> ::std::result::Result + where V: ::serde::de::Visitor + { + self.deserialize(visitor) + } + }; +} + impl de::Deserializer for Decoder { type Error = DecodeError; @@ -186,6 +223,28 @@ impl de::Deserializer for Decoder { let mut d = <() as ValueDeserializer>::into_deserializer(()); d.deserialize(visitor) } + + forward_to_deserialize!{ + deserialize_usize(); + deserialize_u8(); + deserialize_u16(); + deserialize_u32(); + deserialize_isize(); + deserialize_i8(); + deserialize_i16(); + deserialize_i32(); + deserialize_f32(); + deserialize_string(); + deserialize_unit(); + deserialize_seq_fixed_size(len: usize); + deserialize_bytes(); + deserialize_unit_struct(name: &'static str); + deserialize_newtype_struct(name: &'static str); + deserialize_tuple_struct(name: &'static str, len: usize); + deserialize_struct(name: &'static str, fields: &'static [&'static str]); + deserialize_struct_field(); + deserialize_tuple(len: usize); + } } struct VariantVisitor { @@ -270,6 +329,39 @@ impl<'a, I> de::Deserializer for SeqDeserializer<'a, I> { visitor.visit_seq(self) } + + forward_to_deserialize!{ + deserialize_bool(); + deserialize_usize(); + deserialize_u8(); + deserialize_u16(); + deserialize_u32(); + deserialize_u64(); + deserialize_isize(); + deserialize_i8(); + deserialize_i16(); + deserialize_i32(); + deserialize_i64(); + deserialize_f32(); + deserialize_f64(); + deserialize_char(); + deserialize_str(); + deserialize_string(); + deserialize_unit(); + deserialize_option(); + deserialize_seq(); + deserialize_seq_fixed_size(len: usize); + deserialize_bytes(); + deserialize_map(); + deserialize_unit_struct(name: &'static str); + deserialize_newtype_struct(name: &'static str); + deserialize_tuple_struct(name: &'static str, len: usize); + deserialize_struct(name: &'static str, fields: &'static [&'static str]); + deserialize_struct_field(); + deserialize_tuple(len: usize); + deserialize_enum(name: &'static str, variants: &'static [&'static str]); + deserialize_ignored_any(); + } } impl<'a, I> de::SeqVisitor for SeqDeserializer<'a, I> @@ -492,6 +584,38 @@ impl de::Deserializer for UnitDeserializer { { visitor.visit_none() } + + forward_to_deserialize!{ + deserialize_bool(); + deserialize_usize(); + deserialize_u8(); + deserialize_u16(); + deserialize_u32(); + deserialize_u64(); + deserialize_isize(); + deserialize_i8(); + deserialize_i16(); + deserialize_i32(); + deserialize_i64(); + deserialize_f32(); + deserialize_f64(); + deserialize_char(); + deserialize_str(); + deserialize_string(); + deserialize_unit(); + deserialize_seq(); + deserialize_seq_fixed_size(len: usize); + deserialize_bytes(); + deserialize_map(); + deserialize_unit_struct(name: &'static str); + deserialize_newtype_struct(name: &'static str); + deserialize_tuple_struct(name: &'static str, len: usize); + deserialize_struct(name: &'static str, fields: &'static [&'static str]); + deserialize_struct_field(); + deserialize_tuple(len: usize); + deserialize_enum(name: &'static str, variants: &'static [&'static str]); + deserialize_ignored_any(); + } } impl de::Deserialize for Value { diff --git a/src/encoder/serde.rs b/src/encoder/serde.rs index 9c2f602..fcccc3d 100644 --- a/src/encoder/serde.rs +++ b/src/encoder/serde.rs @@ -128,12 +128,15 @@ impl ser::Serializer for Encoder { fn serialize_map(&mut self, _len: Option) -> Result { self.table_begin() } - fn serialize_map_elt(&mut self, _state: &mut Encoder, key: K, value: V) -> Result<(), Error> - where K: ser::Serialize, V: ser::Serialize + fn serialize_map_key(&mut self, _state: &mut Encoder, key: K) -> Result<(), Error> + where K: ser::Serialize { - try!(self.table_key(|me| key.serialize(me))); - try!(value.serialize(self)); - Ok(()) + self.table_key(|me| key.serialize(me)) + } + fn serialize_map_value(&mut self, _state: &mut Encoder, value: V) -> Result<(), Error> + where V: ser::Serialize + { + value.serialize(self) } fn serialize_map_end(&mut self, state: Self) -> Result<(), Error> { self.table_end(state) @@ -144,7 +147,8 @@ impl ser::Serializer for Encoder { fn serialize_struct_elt(&mut self, state: &mut Encoder, key: &'static str, value: V) -> Result<(), Error> where V: ser::Serialize { - self.serialize_map_elt(state, key, value) + try!(self.serialize_map_key(state, key)); + self.serialize_map_value(state, value) } fn serialize_struct_end(&mut self, state: Self) -> Result<(), Error> { self.serialize_map_end(state) @@ -155,7 +159,8 @@ impl ser::Serializer for Encoder { fn serialize_struct_variant_elt(&mut self, state: &mut Encoder, key: &'static str, value: V) -> Result<(), Error> where V: ser::Serialize { - self.serialize_map_elt(state, key, value) + try!(self.serialize_map_key(state, key)); + self.serialize_map_value(state, value) } fn serialize_struct_variant_end(&mut self, state: Self) -> Result<(), Error> { self.serialize_map_end(state) @@ -208,7 +213,8 @@ impl ser::Serialize for Value { Value::Table(ref t) => { let mut state = try!(e.serialize_map(Some(t.len()))); for (k, v) in t.iter() { - try!(e.serialize_map_elt(&mut state, k, v)); + try!(e.serialize_map_key(&mut state, k)); + try!(e.serialize_map_value(&mut state, v)); } e.serialize_map_end(state) } -- cgit v1.2.3 From 86b9259616ed05fe32c5eee233b65e7934a76666 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Thu, 28 Jul 2016 11:08:39 -0700 Subject: Cfg off functions only needed for rustc-serialize or serde --- src/decoder/mod.rs | 40 +++++++++++++++++++++++++++------------- src/encoder/mod.rs | 4 ++++ 2 files changed, 31 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/decoder/mod.rs b/src/decoder/mod.rs index b223e03..9720528 100644 --- a/src/decoder/mod.rs +++ b/src/decoder/mod.rs @@ -1,6 +1,9 @@ use std::error; use std::fmt; + +#[cfg(feature = "rustc-serialize")] use std::collections::{btree_map, BTreeMap}; +#[cfg(feature = "rustc-serialize")] use std::iter::Peekable; use Value; @@ -19,7 +22,9 @@ pub struct Decoder { /// whether fields were decoded or not. pub toml: Option, cur_field: Option, + #[cfg(feature = "rustc-serialize")] cur_map: Peekable>, + #[cfg(feature = "rustc-serialize")] leftover_map: ::Table, } @@ -115,27 +120,36 @@ impl Decoder { /// This decoder can be passed to the `Decodable` methods or driven /// manually. pub fn new(toml: Value) -> Decoder { + Decoder::new_empty(Some(toml), None) + } + + fn sub_decoder(&self, toml: Option, field: &str) -> Decoder { + let cur_field = if field.is_empty() { + self.cur_field.clone() + } else { + match self.cur_field { + None => Some(field.to_string()), + Some(ref s) => Some(format!("{}.{}", s, field)) + } + }; + Decoder::new_empty(toml, cur_field) + } + + #[cfg(feature = "rustc-serialize")] + fn new_empty(toml: Option, cur_field: Option) -> Decoder { Decoder { - toml: Some(toml), - cur_field: None, + toml: toml, + cur_field: cur_field, leftover_map: BTreeMap::new(), cur_map: BTreeMap::new().into_iter().peekable(), } } - fn sub_decoder(&self, toml: Option, field: &str) -> Decoder { + #[cfg(not(feature = "rustc-serialize"))] + fn new_empty(toml: Option, cur_field: Option) -> Decoder { Decoder { toml: toml, - cur_field: if field.is_empty() { - self.cur_field.clone() - } else { - match self.cur_field { - None => Some(field.to_string()), - Some(ref s) => Some(format!("{}.{}", s, field)) - } - }, - leftover_map: BTreeMap::new(), - cur_map: BTreeMap::new().into_iter().peekable(), + cur_field: cur_field, } } diff --git a/src/encoder/mod.rs b/src/encoder/mod.rs index 0f13b81..fb00a47 100644 --- a/src/encoder/mod.rs +++ b/src/encoder/mod.rs @@ -113,6 +113,7 @@ impl Encoder { } } + #[cfg(feature = "rustc-serialize")] fn seq(&mut self, f: F) -> Result<(), Error> where F: FnOnce(&mut Encoder) -> Result<(), Error> { @@ -132,6 +133,7 @@ impl Encoder { } } + #[cfg(feature = "rustc-serialize")] fn table(&mut self, f: F) -> Result<(), Error> where F: FnOnce(&mut Encoder) -> Result<(), Error> { @@ -154,6 +156,7 @@ impl Encoder { } } + #[cfg(feature = "serde")] fn table_begin(&mut self) -> Result { match self.state { State::NextMapKey => Err(Error::InvalidMapKeyLocation), @@ -161,6 +164,7 @@ impl Encoder { } } + #[cfg(feature = "serde")] fn table_end(&mut self, mut state: Self) -> Result<(), Error> { match state.state { State::NextKey(key) => { -- cgit v1.2.3 From dca3eca564ac53620b0f8f66c76675bfc8c62203 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Fri, 29 Jul 2016 00:55:52 -0700 Subject: Restore defaulted Deserializer methods --- src/decoder/serde.rs | 141 ++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 123 insertions(+), 18 deletions(-) (limited to 'src') diff --git a/src/decoder/serde.rs b/src/decoder/serde.rs index d854046..81a2bae 100644 --- a/src/decoder/serde.rs +++ b/src/decoder/serde.rs @@ -80,6 +80,27 @@ impl de::Deserializer for Decoder { } } + fn deserialize_i8(&mut self, visitor: V) + -> Result + where V: de::Visitor + { + self.deserialize_i64(visitor) + } + + fn deserialize_i16(&mut self, visitor: V) + -> Result + where V: de::Visitor + { + self.deserialize_i64(visitor) + } + + fn deserialize_i32(&mut self, visitor: V) + -> Result + where V: de::Visitor + { + self.deserialize_i64(visitor) + } + fn deserialize_i64(&mut self, mut visitor: V) -> Result where V: de::Visitor @@ -90,10 +111,53 @@ impl de::Deserializer for Decoder { } } - fn deserialize_u64(&mut self, v: V) -> Result + fn deserialize_isize(&mut self, visitor: V) + -> Result where V: de::Visitor { - self.deserialize_i64(v) + self.deserialize_i64(visitor) + } + + fn deserialize_u8(&mut self, visitor: V) + -> Result + where V: de::Visitor + { + self.deserialize_i64(visitor) + } + + fn deserialize_u16(&mut self, visitor: V) + -> Result + where V: de::Visitor + { + self.deserialize_i64(visitor) + } + + fn deserialize_u32(&mut self, visitor: V) + -> Result + where V: de::Visitor + { + self.deserialize_i64(visitor) + } + + fn deserialize_u64(&mut self, visitor: V) + -> Result + where V: de::Visitor + { + self.deserialize_i64(visitor) + } + + fn deserialize_usize(&mut self, visitor: V) + -> Result + where V: de::Visitor + { + self.deserialize_i64(visitor) + } + + fn deserialize_f32(&mut self, visitor: V) + -> Result + where V: de::Visitor + { + self.deserialize_f64(visitor) } fn deserialize_f64(&mut self, mut visitor: V) @@ -116,6 +180,13 @@ impl de::Deserializer for Decoder { } } + fn deserialize_string(&mut self, visitor: V) + -> Result + where V: de::Visitor, + { + self.deserialize_str(visitor) + } + fn deserialize_char(&mut self, mut visitor: V) -> Result where V: de::Visitor @@ -224,26 +295,60 @@ impl de::Deserializer for Decoder { d.deserialize(visitor) } + fn deserialize_bytes(&mut self, visitor: V) + -> Result + where V: de::Visitor + { + self.deserialize_seq(visitor) + } + + fn deserialize_seq_fixed_size(&mut self, _len: usize, visitor: V) + -> Result + where V: de::Visitor + { + self.deserialize_seq(visitor) + } + + fn deserialize_newtype_struct(&mut self, _name: &'static str, visitor: V) + -> Result + where V: de::Visitor + { + self.deserialize_seq(visitor) + } + + fn deserialize_tuple_struct(&mut self, + _name: &'static str, + _len: usize, + visitor: V) + -> Result + where V: de::Visitor + { + self.deserialize_seq(visitor) + } + + fn deserialize_struct(&mut self, + _name: &'static str, + _fields: &'static [&'static str], + visitor: V) + -> Result + where V: de::Visitor + { + self.deserialize_map(visitor) + } + + fn deserialize_tuple(&mut self, + _len: usize, + visitor: V) + -> Result + where V: de::Visitor + { + self.deserialize_seq(visitor) + } + forward_to_deserialize!{ - deserialize_usize(); - deserialize_u8(); - deserialize_u16(); - deserialize_u32(); - deserialize_isize(); - deserialize_i8(); - deserialize_i16(); - deserialize_i32(); - deserialize_f32(); - deserialize_string(); deserialize_unit(); - deserialize_seq_fixed_size(len: usize); - deserialize_bytes(); deserialize_unit_struct(name: &'static str); - deserialize_newtype_struct(name: &'static str); - deserialize_tuple_struct(name: &'static str, len: usize); - deserialize_struct(name: &'static str, fields: &'static [&'static str]); deserialize_struct_field(); - deserialize_tuple(len: usize); } } -- cgit v1.2.3