aboutsummaryrefslogtreecommitdiff
path: root/src/decoder
diff options
context:
space:
mode:
authorDavid Tolnay <dtolnay@gmail.com>2016-07-28 11:01:22 -0700
committerDavid Tolnay <dtolnay@gmail.com>2016-07-28 11:09:40 -0700
commitd858c1f2d06f977b4d3c26ea82c72eb04bcf5fad (patch)
tree17c96e83fd70ce3cf0fde88560dc32ffdb8ff138 /src/decoder
parentf0659e10783cc81ba64095fbac9a53eb5da91716 (diff)
downloadmilf-rs-d858c1f2d06f977b4d3c26ea82c72eb04bcf5fad.tar.gz
milf-rs-d858c1f2d06f977b4d3c26ea82c72eb04bcf5fad.zip
Update to serde 0.8.0
Diffstat (limited to 'src/decoder')
-rw-r--r--src/decoder/serde.rs124
1 files changed, 124 insertions, 0 deletions
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<V>(
+ &mut self,
+ $(_: $ty,)*
+ _visitor: V,
+ ) -> ::std::result::Result<V::Value, Self::Error>
+ 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<V>(
+ &mut self,
+ $(_: $ty,)*
+ visitor: V,
+ ) -> ::std::result::Result<V::Value, Self::Error>
+ 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<Self::Error>>::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 {