renamed serialization to Serializable and Deserializable
This commit is contained in:
parent
0747fece03
commit
b9edeff434
|
@ -1,20 +1,20 @@
|
|||
use {syn, quote};
|
||||
|
||||
pub fn impl_raw_deserialize(ast: &syn::DeriveInput) -> quote::Tokens {
|
||||
pub fn impl_deserializable(ast: &syn::DeriveInput) -> quote::Tokens {
|
||||
let body = match ast.body {
|
||||
syn::Body::Struct(ref s) => s,
|
||||
_ => panic!("#[derive(RawDeserialize)] is only defined for structs."),
|
||||
_ => panic!("#[derive(Deserializable)] is only defined for structs."),
|
||||
};
|
||||
|
||||
let stmts: Vec<_> = match *body {
|
||||
syn::VariantData::Struct(ref fields) => fields.iter().enumerate().map(deserialize_field_map).collect(),
|
||||
syn::VariantData::Tuple(ref fields) => fields.iter().enumerate().map(deserialize_field_map).collect(),
|
||||
syn::VariantData::Unit => panic!("#[derive(RawDeserialize)] is not defined for Unit structs."),
|
||||
syn::VariantData::Unit => panic!("#[derive(Deserializable)] is not defined for Unit structs."),
|
||||
};
|
||||
|
||||
let name = &ast.ident;
|
||||
|
||||
let dummy_const = syn::Ident::new(format!("_IMPL_RAW_DESERIALIZE_FOR_{}", name));
|
||||
let dummy_const = syn::Ident::new(format!("_IMPL_DESERIALIZABLE_FOR_{}", name));
|
||||
let impl_block = quote! {
|
||||
impl serialization::Deserializable for #name {
|
||||
fn deserialize<T>(reader: &mut serialization::Reader<T>) -> Result<Self, serialization::Error> where T: io::Read {
|
||||
|
|
|
@ -7,22 +7,22 @@ mod ser;
|
|||
mod de;
|
||||
|
||||
use proc_macro::TokenStream;
|
||||
use ser::impl_raw_serialize;
|
||||
use de::impl_raw_deserialize;
|
||||
use ser::impl_serializable;
|
||||
use de::impl_deserializable;
|
||||
|
||||
#[proc_macro_derive(RawSerialize)]
|
||||
#[proc_macro_derive(Serializable)]
|
||||
pub fn raw_serialize(input: TokenStream) -> TokenStream {
|
||||
let s = input.to_string();
|
||||
let ast = syn::parse_derive_input(&s).unwrap();
|
||||
let gen = impl_raw_serialize(&ast);
|
||||
let gen = impl_serializable(&ast);
|
||||
gen.parse().unwrap()
|
||||
}
|
||||
|
||||
#[proc_macro_derive(RawDeserialize)]
|
||||
pub fn raw_deserialize(input: TokenStream) -> TokenStream {
|
||||
#[proc_macro_derive(Deserializable)]
|
||||
pub fn deserializable(input: TokenStream) -> TokenStream {
|
||||
let s = input.to_string();
|
||||
let ast = syn::parse_derive_input(&s).unwrap();
|
||||
let gen = impl_raw_deserialize(&ast);
|
||||
let gen = impl_deserializable(&ast);
|
||||
gen.parse().unwrap()
|
||||
}
|
||||
|
||||
|
|
|
@ -1,20 +1,20 @@
|
|||
use {syn, quote};
|
||||
|
||||
pub fn impl_raw_serialize(ast: &syn::DeriveInput) -> quote::Tokens {
|
||||
pub fn impl_serializable(ast: &syn::DeriveInput) -> quote::Tokens {
|
||||
let body = match ast.body {
|
||||
syn::Body::Struct(ref s) => s,
|
||||
_ => panic!("#[derive(RawSerialize)] is only defined for structs."),
|
||||
_ => panic!("#[derive(Serializable)] is only defined for structs."),
|
||||
};
|
||||
|
||||
let stmts: Vec<_> = match *body {
|
||||
syn::VariantData::Struct(ref fields) => fields.iter().enumerate().map(serialize_field_map).collect(),
|
||||
syn::VariantData::Tuple(ref fields) => fields.iter().enumerate().map(serialize_field_map).collect(),
|
||||
syn::VariantData::Unit => panic!("#[derive(RawSerialize)] is not defined for Unit structs."),
|
||||
syn::VariantData::Unit => panic!("#[derive(Serializable)] is not defined for Unit structs."),
|
||||
};
|
||||
|
||||
let name = &ast.ident;
|
||||
|
||||
let dummy_const = syn::Ident::new(format!("_IMPL_RAW_SERIALIZE_FOR_{}", name));
|
||||
let dummy_const = syn::Ident::new(format!("_IMPL_SERIALIZABLE_FOR_{}", name));
|
||||
let impl_block = quote! {
|
||||
impl serialization::Serializable for #name {
|
||||
fn serialize(&self, stream: &mut serialization::Stream) {
|
||||
|
|
|
@ -4,7 +4,7 @@ extern crate serialization_derive;
|
|||
|
||||
use serialization::{serialize, deserialize};
|
||||
|
||||
#[derive(Debug, PartialEq, RawSerialize, RawDeserialize)]
|
||||
#[derive(Debug, PartialEq, Serializable, Deserializable)]
|
||||
struct Foo {
|
||||
a: u8,
|
||||
b: u16,
|
||||
|
@ -12,7 +12,7 @@ struct Foo {
|
|||
d: u64,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, RawSerialize, RawDeserialize)]
|
||||
#[derive(Debug, PartialEq, Serializable, Deserializable)]
|
||||
struct Bar {
|
||||
a: Vec<Foo>,
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue