Skip to content
This repository has been archived by the owner on Mar 25, 2024. It is now read-only.

Commit

Permalink
Merge pull request #22 from dtolnay/push_ser
Browse files Browse the repository at this point in the history
serde push-serialization
  • Loading branch information
dtolnay authored Jul 25, 2016
2 parents 71771bf + f144016 commit 8e12d0f
Show file tree
Hide file tree
Showing 7 changed files with 355 additions and 93 deletions.
2 changes: 1 addition & 1 deletion yaml/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ preserve_order = ["yaml-rust/preserve_order"]

[dependencies]
clippy = { version = "^0.*", optional = true }
serde = "^0.7"
serde = "0.8.0-rc3"
yaml-rust = "^0.3.3"
62 changes: 62 additions & 0 deletions yaml/src/de.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,38 @@ impl<'a> de::MapVisitor for MapVisitor<'a> {
{
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();
}
}

let mut de = MissingFieldDeserializer(field);
Expand Down Expand Up @@ -271,6 +303,36 @@ impl<'a> de::Deserializer for Deserializer<'a> {
_ => Err(Error::VariantNotAMapOrString(String::from(name))),
}
}

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_tuple_struct(name: &'static str, len: usize);
deserialize_struct(name: &'static str, fields: &'static [&'static str]);
deserialize_struct_field();
deserialize_tuple(len: usize);
deserialize_ignored_any();
}
}

/// Decodes a YAML value from a `&str`.
Expand Down
37 changes: 37 additions & 0 deletions yaml/src/forward.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#[macro_export]
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)
}
};
}
3 changes: 3 additions & 0 deletions yaml/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ pub use self::ser::{Serializer, to_string, to_vec, to_writer};
pub use self::value::{Value, from_value, to_value};
pub use self::error::{Error, Result};

#[macro_use]
mod forward;

pub mod de;
pub mod ser;
pub mod value;
Expand Down
Loading

0 comments on commit 8e12d0f

Please sign in to comment.