mirror of
https://github.com/pezkuwichain/serde.git
synced 2026-04-26 03:57:56 +00:00
Compare commits
15 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 85c95040b3 | |||
| 339c0f5493 | |||
| b4d5c26f4e | |||
| f4e1ffa2cb | |||
| ef5d09e144 | |||
| e547a06639 | |||
| c61b20cceb | |||
| 42987a5b24 | |||
| 3f28a93240 | |||
| 9970084550 | |||
| 3920993370 | |||
| 22690cedc2 | |||
| b27039d34d | |||
| 1b6fd5a362 | |||
| 8b7b886036 |
+1
-1
@@ -24,7 +24,7 @@ script:
|
|||||||
- (cd serde && travis-cargo --only nightly build -- --no-default-features --features collections)
|
- (cd serde && travis-cargo --only nightly build -- --no-default-features --features collections)
|
||||||
- (cd testing && travis-cargo --skip nightly test)
|
- (cd testing && travis-cargo --skip nightly test)
|
||||||
- (cd testing && travis-cargo --only nightly test -- --features unstable-testing)
|
- (cd testing && travis-cargo --only nightly test -- --features unstable-testing)
|
||||||
- (cd serde_macros && travis-cargo --only nightly test -- --features unstable-testing)
|
- (cd serde_derive && travis-cargo --only nightly test)
|
||||||
- (cd examples/serde-syntex-example && travis-cargo --skip nightly run)
|
- (cd examples/serde-syntex-example && travis-cargo --skip nightly run)
|
||||||
- (cd examples/serde-syntex-example && travis-cargo --only nightly run -- --no-default-features --features unstable)
|
- (cd examples/serde-syntex-example && travis-cargo --only nightly run -- --no-default-features --features unstable)
|
||||||
- (cd serde && travis-cargo --only stable doc)
|
- (cd serde && travis-cargo --only stable doc)
|
||||||
|
|||||||
@@ -15,8 +15,10 @@ You may be looking for:
|
|||||||
## Serde in action
|
## Serde in action
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
#![feature(plugin, custom_derive)]
|
#![feature(proc_macro)]
|
||||||
#![plugin(serde_macros)]
|
|
||||||
|
#[macro_use]
|
||||||
|
extern crate serde_derive;
|
||||||
|
|
||||||
extern crate serde_json;
|
extern crate serde_json;
|
||||||
|
|
||||||
|
|||||||
@@ -6,12 +6,12 @@ build = "build.rs"
|
|||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["serde_codegen"]
|
default = ["serde_codegen"]
|
||||||
unstable = ["serde_macros"]
|
unstable = ["serde_derive"]
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
serde_codegen = { version = "^0.8", optional = true, path = "../../serde_codegen" }
|
serde_codegen = { version = "^0.8", optional = true, path = "../../serde_codegen" }
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
serde = "^0.8"
|
serde = "^0.8"
|
||||||
|
serde_derive = { version = "^0.8", optional = true, path = "../../serde_derive" }
|
||||||
serde_json = "^0.8"
|
serde_json = "^0.8"
|
||||||
serde_macros = { version = "^0.8", optional = true, path = "../../serde_macros" }
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#[cfg(not(feature = "serde_macros"))]
|
#[cfg(not(feature = "serde_derive"))]
|
||||||
mod inner {
|
mod inner {
|
||||||
extern crate serde_codegen;
|
extern crate serde_codegen;
|
||||||
|
|
||||||
@@ -15,7 +15,7 @@ mod inner {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "serde_macros")]
|
#[cfg(feature = "serde_derive")]
|
||||||
mod inner {
|
mod inner {
|
||||||
pub fn main() {}
|
pub fn main() {}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,14 @@
|
|||||||
#![cfg_attr(feature = "serde_macros", feature(custom_derive, plugin))]
|
#![cfg_attr(feature = "serde_derive", feature(proc_macro))]
|
||||||
#![cfg_attr(feature = "serde_macros", plugin(serde_macros))]
|
|
||||||
|
#[cfg(feature = "serde_derive")]
|
||||||
|
#[macro_use]
|
||||||
|
extern crate serde_derive;
|
||||||
|
|
||||||
extern crate serde;
|
extern crate serde;
|
||||||
extern crate serde_json;
|
extern crate serde_json;
|
||||||
|
|
||||||
#[cfg(feature = "serde_macros")]
|
#[cfg(feature = "serde_derive")]
|
||||||
include!("main.rs.in");
|
include!("main.rs.in");
|
||||||
|
|
||||||
#[cfg(not(feature = "serde_macros"))]
|
#[cfg(not(feature = "serde_derive"))]
|
||||||
include!(concat!(env!("OUT_DIR"), "/main.rs"));
|
include!(concat!(env!("OUT_DIR"), "/main.rs"));
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "serde"
|
name = "serde"
|
||||||
version = "0.8.10"
|
version = "0.8.12"
|
||||||
authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>"]
|
authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>"]
|
||||||
license = "MIT/Apache-2.0"
|
license = "MIT/Apache-2.0"
|
||||||
description = "A generic serialization/deserialization framework"
|
description = "A generic serialization/deserialization framework"
|
||||||
|
|||||||
@@ -809,7 +809,7 @@ map_impl!(
|
|||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#[cfg(all(feature = "unstable", feature = "std"))]
|
#[cfg(feature = "std")]
|
||||||
impl Deserialize for net::IpAddr {
|
impl Deserialize for net::IpAddr {
|
||||||
fn deserialize<D>(deserializer: &mut D) -> Result<Self, D::Error>
|
fn deserialize<D>(deserializer: &mut D) -> Result<Self, D::Error>
|
||||||
where D: Deserializer,
|
where D: Deserializer,
|
||||||
|
|||||||
@@ -640,15 +640,12 @@ impl Serialize for Duration {
|
|||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#[cfg(all(feature = "std", feature = "unstable"))]
|
#[cfg(feature = "std")]
|
||||||
impl Serialize for net::IpAddr {
|
impl Serialize for net::IpAddr {
|
||||||
fn serialize<S>(&self, serializer: &mut S) -> Result<(), S::Error>
|
fn serialize<S>(&self, serializer: &mut S) -> Result<(), S::Error>
|
||||||
where S: Serializer,
|
where S: Serializer,
|
||||||
{
|
{
|
||||||
match *self {
|
self.to_string().serialize(serializer)
|
||||||
net::IpAddr::V4(ref addr) => addr.serialize(serializer),
|
|
||||||
net::IpAddr::V6(ref addr) => addr.serialize(serializer),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "serde_codegen"
|
name = "serde_codegen"
|
||||||
version = "0.8.10"
|
version = "0.8.12"
|
||||||
authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>"]
|
authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>"]
|
||||||
license = "MIT/Apache-2.0"
|
license = "MIT/Apache-2.0"
|
||||||
description = "Macros to auto-generate implementations for the serde framework"
|
description = "Macros to auto-generate implementations for the serde framework"
|
||||||
@@ -22,8 +22,8 @@ with-syn = []
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
clippy = { version = "^0.*", optional = true }
|
clippy = { version = "^0.*", optional = true }
|
||||||
quote = "0.2"
|
quote = "0.3"
|
||||||
serde_codegen_internals = { version = "=0.9.0", default-features = false, path = "../serde_codegen_internals" }
|
serde_codegen_internals = { version = "=0.10.0", default-features = false, path = "../serde_codegen_internals" }
|
||||||
syn = { version = "0.8", features = ["aster", "visit"] }
|
syn = { version = "0.9", features = ["aster", "visit"] }
|
||||||
syntex = { version = "^0.44.0", optional = true }
|
syntex = { version = "^0.44.0", optional = true }
|
||||||
syntex_syntax = { version = "^0.44.0", optional = true }
|
syntex_syntax = { version = "^0.44.0", optional = true }
|
||||||
|
|||||||
+25
-32
@@ -185,17 +185,17 @@ fn deserialize_visitor(generics: &syn::Generics) -> (Tokens, Tokens, Tokens) {
|
|||||||
let ty_param_idents = if ty_param_idents.is_empty() {
|
let ty_param_idents = if ty_param_idents.is_empty() {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
Some(quote!(::<#(ty_param_idents),*>))
|
Some(quote!(::<#(#ty_param_idents),*>))
|
||||||
};
|
};
|
||||||
|
|
||||||
let phantom_exprs = iter::repeat(quote!(::std::marker::PhantomData)).take(num_phantoms);
|
let phantom_exprs = iter::repeat(quote!(::std::marker::PhantomData)).take(num_phantoms);
|
||||||
|
|
||||||
(
|
(
|
||||||
quote! {
|
quote! {
|
||||||
struct __Visitor #generics ( #(phantom_types),* ) #where_clause;
|
struct __Visitor #generics ( #(#phantom_types),* ) #where_clause;
|
||||||
},
|
},
|
||||||
quote!(__Visitor <#(all_params),*> ),
|
quote!(__Visitor <#(#all_params),*> ),
|
||||||
quote!(__Visitor #ty_param_idents ( #(phantom_exprs),* )),
|
quote!(__Visitor #ty_param_idents ( #(#phantom_exprs),* )),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -358,17 +358,17 @@ fn deserialize_seq(
|
|||||||
quote!(#ident: #value)
|
quote!(#ident: #value)
|
||||||
});
|
});
|
||||||
quote! {
|
quote! {
|
||||||
#type_path { #(args),* }
|
#type_path { #(#args),* }
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let args = (0..fields.len()).map(|i| aster::id(format!("__field{}", i)));
|
let args = (0..fields.len()).map(|i| aster::id(format!("__field{}", i)));
|
||||||
quote! {
|
quote! {
|
||||||
#type_path ( #(args),* )
|
#type_path ( #(#args),* )
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
quote! {
|
quote! {
|
||||||
#(let_values)*
|
#(#let_values)*
|
||||||
|
|
||||||
try!(visitor.end());
|
try!(visitor.end());
|
||||||
|
|
||||||
@@ -505,7 +505,7 @@ fn deserialize_item_enum(
|
|||||||
let variant_names = variants.iter().map(|variant| variant.ident.to_string());
|
let variant_names = variants.iter().map(|variant| variant.ident.to_string());
|
||||||
|
|
||||||
let variants_stmt = quote! {
|
let variants_stmt = quote! {
|
||||||
const VARIANTS: &'static [&'static str] = &[ #(variant_names),* ];
|
const VARIANTS: &'static [&'static str] = &[ #(#variant_names),* ];
|
||||||
};
|
};
|
||||||
|
|
||||||
let ignored_arm = if item_attrs.deny_unknown_fields() {
|
let ignored_arm = if item_attrs.deny_unknown_fields() {
|
||||||
@@ -551,7 +551,7 @@ fn deserialize_item_enum(
|
|||||||
where __V: _serde::de::VariantVisitor,
|
where __V: _serde::de::VariantVisitor,
|
||||||
{
|
{
|
||||||
match try!(visitor.visit_variant()) {
|
match try!(visitor.visit_variant()) {
|
||||||
#(variant_arms)*
|
#(#variant_arms)*
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -651,14 +651,6 @@ fn deserialize_field_visitor(
|
|||||||
Some(quote!(__ignore,))
|
Some(quote!(__ignore,))
|
||||||
};
|
};
|
||||||
|
|
||||||
let field_enum = quote! {
|
|
||||||
#[allow(non_camel_case_types)]
|
|
||||||
enum __Field {
|
|
||||||
#(field_idents,)*
|
|
||||||
#ignore_variant
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
let index_field_arms: Vec<_> = field_idents.iter()
|
let index_field_arms: Vec<_> = field_idents.iter()
|
||||||
.enumerate()
|
.enumerate()
|
||||||
.map(|(field_index, field_ident)| {
|
.map(|(field_index, field_ident)| {
|
||||||
@@ -686,7 +678,7 @@ fn deserialize_field_visitor(
|
|||||||
|
|
||||||
let index_body = quote! {
|
let index_body = quote! {
|
||||||
match value {
|
match value {
|
||||||
#(index_field_arms)*
|
#(#index_field_arms)*
|
||||||
_ => #fallthrough_index_arm_expr
|
_ => #fallthrough_index_arm_expr
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -712,7 +704,7 @@ fn deserialize_field_visitor(
|
|||||||
|
|
||||||
let str_body = quote! {
|
let str_body = quote! {
|
||||||
match value {
|
match value {
|
||||||
#(str_field_arms)*
|
#(#str_field_arms)*
|
||||||
_ => #fallthrough_str_arm_expr
|
_ => #fallthrough_str_arm_expr
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -740,12 +732,18 @@ fn deserialize_field_visitor(
|
|||||||
|
|
||||||
let bytes_body = quote! {
|
let bytes_body = quote! {
|
||||||
match value {
|
match value {
|
||||||
#(bytes_field_arms)*
|
#(#bytes_field_arms)*
|
||||||
_ => #fallthrough_bytes_arm_expr
|
_ => #fallthrough_bytes_arm_expr
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let impl_item = quote! {
|
quote! {
|
||||||
|
#[allow(non_camel_case_types)]
|
||||||
|
enum __Field {
|
||||||
|
#(#field_idents,)*
|
||||||
|
#ignore_variant
|
||||||
|
}
|
||||||
|
|
||||||
impl _serde::de::Deserialize for __Field {
|
impl _serde::de::Deserialize for __Field {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn deserialize<__D>(deserializer: &mut __D) -> ::std::result::Result<__Field, __D::Error>
|
fn deserialize<__D>(deserializer: &mut __D) -> ::std::result::Result<__Field, __D::Error>
|
||||||
@@ -778,11 +776,6 @@ fn deserialize_field_visitor(
|
|||||||
deserializer.deserialize_struct_field(__FieldVisitor)
|
deserializer.deserialize_struct_field(__FieldVisitor)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
quote! {
|
|
||||||
#field_enum
|
|
||||||
#impl_item
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -816,7 +809,7 @@ fn deserialize_struct_visitor(
|
|||||||
});
|
});
|
||||||
|
|
||||||
let fields_stmt = quote! {
|
let fields_stmt = quote! {
|
||||||
const FIELDS: &'static [&'static str] = &[ #(field_names),* ];
|
const FIELDS: &'static [&'static str] = &[ #(#field_names),* ];
|
||||||
};
|
};
|
||||||
|
|
||||||
(field_visitor, fields_stmt, visit_map)
|
(field_visitor, fields_stmt, visit_map)
|
||||||
@@ -929,21 +922,21 @@ fn deserialize_map(
|
|||||||
});
|
});
|
||||||
|
|
||||||
quote! {
|
quote! {
|
||||||
#(let_values)*
|
#(#let_values)*
|
||||||
|
|
||||||
while let Some(key) = try!(visitor.visit_key::<__Field>()) {
|
while let Some(key) = try!(visitor.visit_key::<__Field>()) {
|
||||||
match key {
|
match key {
|
||||||
#(value_arms)*
|
#(#value_arms)*
|
||||||
#(skipped_arms)*
|
#(#skipped_arms)*
|
||||||
#ignored_arm
|
#ignored_arm
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
try!(visitor.end());
|
try!(visitor.end());
|
||||||
|
|
||||||
#(extract_values)*
|
#(#extract_values)*
|
||||||
|
|
||||||
Ok(#struct_path { #(result),* })
|
Ok(#struct_path { #(#result),* })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -201,7 +201,7 @@ pub fn expand_single_item(item: &str) -> Result<String, String> {
|
|||||||
let mut de = false;
|
let mut de = false;
|
||||||
let item = syn::MacroInput {
|
let item = syn::MacroInput {
|
||||||
attrs: item.attrs.into_iter().flat_map(|attr| {
|
attrs: item.attrs.into_iter().flat_map(|attr| {
|
||||||
if attr.is_sugared_doc {
|
if attr.is_sugared_doc || attr.style != syn::AttrStyle::Outer {
|
||||||
return Some(attr);
|
return Some(attr);
|
||||||
}
|
}
|
||||||
let (name, nested) = match attr.value {
|
let (name, nested) = match attr.value {
|
||||||
@@ -210,6 +210,7 @@ pub fn expand_single_item(item: &str) -> Result<String, String> {
|
|||||||
};
|
};
|
||||||
if name != "derive" {
|
if name != "derive" {
|
||||||
return Some(syn::Attribute {
|
return Some(syn::Attribute {
|
||||||
|
style: syn::AttrStyle::Outer,
|
||||||
value: syn::MetaItem::List(name, nested),
|
value: syn::MetaItem::List(name, nested),
|
||||||
is_sugared_doc: false,
|
is_sugared_doc: false,
|
||||||
});
|
});
|
||||||
@@ -231,6 +232,7 @@ pub fn expand_single_item(item: &str) -> Result<String, String> {
|
|||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
Some(syn::Attribute {
|
Some(syn::Attribute {
|
||||||
|
style: syn::AttrStyle::Outer,
|
||||||
value: syn::MetaItem::List(name, rest),
|
value: syn::MetaItem::List(name, rest),
|
||||||
is_sugared_doc: false,
|
is_sugared_doc: false,
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -168,7 +168,7 @@ fn serialize_tuple_struct(
|
|||||||
|
|
||||||
quote! {
|
quote! {
|
||||||
let #let_mut __serde_state = try!(_serializer.serialize_tuple_struct(#type_name, #len));
|
let #let_mut __serde_state = try!(_serializer.serialize_tuple_struct(#type_name, #len));
|
||||||
#(serialize_stmts)*
|
#(#serialize_stmts)*
|
||||||
_serializer.serialize_tuple_struct_end(__serde_state)
|
_serializer.serialize_tuple_struct_end(__serde_state)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -209,7 +209,7 @@ fn serialize_struct(
|
|||||||
|
|
||||||
quote! {
|
quote! {
|
||||||
let #let_mut __serde_state = try!(_serializer.serialize_struct(#type_name, #len));
|
let #let_mut __serde_state = try!(_serializer.serialize_struct(#type_name, #len));
|
||||||
#(serialize_fields)*
|
#(#serialize_fields)*
|
||||||
_serializer.serialize_struct_end(__serde_state)
|
_serializer.serialize_struct_end(__serde_state)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -238,7 +238,7 @@ fn serialize_item_enum(
|
|||||||
|
|
||||||
quote! {
|
quote! {
|
||||||
match *self {
|
match *self {
|
||||||
#(arms)*
|
#(#arms)*
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -290,7 +290,7 @@ fn serialize_variant(
|
|||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let pat = quote!(#type_ident::#variant_ident(#(field_names),*));
|
let pat = quote!(#type_ident::#variant_ident(#(#field_names),*));
|
||||||
|
|
||||||
let block = serialize_tuple_variant(
|
let block = serialize_tuple_variant(
|
||||||
type_name,
|
type_name,
|
||||||
@@ -313,7 +313,7 @@ fn serialize_variant(
|
|||||||
};
|
};
|
||||||
quote!(ref #id)
|
quote!(ref #id)
|
||||||
});
|
});
|
||||||
let pat = quote!(#type_ident::#variant_ident { #(fields),* });
|
let pat = quote!(#type_ident::#variant_ident { #(#fields),* });
|
||||||
|
|
||||||
let block = serialize_struct_variant(
|
let block = serialize_struct_variant(
|
||||||
variant_index,
|
variant_index,
|
||||||
@@ -381,7 +381,7 @@ fn serialize_tuple_variant(
|
|||||||
#variant_index,
|
#variant_index,
|
||||||
#variant_name,
|
#variant_name,
|
||||||
#len));
|
#len));
|
||||||
#(serialize_stmts)*
|
#(#serialize_stmts)*
|
||||||
_serializer.serialize_tuple_variant_end(__serde_state)
|
_serializer.serialize_tuple_variant_end(__serde_state)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -428,7 +428,7 @@ fn serialize_struct_variant(
|
|||||||
#variant_name,
|
#variant_name,
|
||||||
#len,
|
#len,
|
||||||
));
|
));
|
||||||
#(serialize_fields)*
|
#(#serialize_fields)*
|
||||||
_serializer.serialize_struct_variant_end(__serde_state)
|
_serializer.serialize_struct_variant_end(__serde_state)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "serde_codegen_internals"
|
name = "serde_codegen_internals"
|
||||||
version = "0.9.0"
|
version = "0.10.0"
|
||||||
authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>"]
|
authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>"]
|
||||||
license = "MIT/Apache-2.0"
|
license = "MIT/Apache-2.0"
|
||||||
description = "AST representation used by Serde codegen. Unstable."
|
description = "AST representation used by Serde codegen. Unstable."
|
||||||
@@ -15,4 +15,4 @@ unstable-testing = ["clippy"]
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
clippy = { version = "^0.*", optional = true }
|
clippy = { version = "^0.*", optional = true }
|
||||||
syn = "0.8"
|
syn = "0.9"
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "serde_derive"
|
name = "serde_derive"
|
||||||
version = "0.8.10"
|
version = "0.8.12"
|
||||||
authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>"]
|
authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>"]
|
||||||
license = "MIT/Apache-2.0"
|
license = "MIT/Apache-2.0"
|
||||||
description = "Macros 1.1 implementation of #[derive(Serialize, Deserialize)]"
|
description = "Macros 1.1 implementation of #[derive(Serialize, Deserialize)]"
|
||||||
@@ -12,15 +12,16 @@ include = ["Cargo.toml", "src/**/*.rs"]
|
|||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
name = "serde_derive"
|
name = "serde_derive"
|
||||||
rustc-macro = true
|
proc-macro = true
|
||||||
|
|
||||||
[dependencies.serde_codegen]
|
[dependencies.serde_codegen]
|
||||||
version = "=0.8.10"
|
version = "=0.8.12"
|
||||||
path = "../serde_codegen"
|
path = "../serde_codegen"
|
||||||
default-features = false
|
default-features = false
|
||||||
features = ["with-syn"]
|
features = ["with-syn"]
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
|
compiletest_rs = "^0.2.0"
|
||||||
fnv = "1.0"
|
fnv = "1.0"
|
||||||
serde = { version = "0.8.10", path = "../serde" }
|
serde = { version = "0.8.12", path = "../serde" }
|
||||||
serde_test = { version = "0.8.10", path = "../serde_test" }
|
serde_test = { version = "0.8.12", path = "../serde_test" }
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
#![feature(rustc_macro, rustc_macro_lib)]
|
#![feature(proc_macro, proc_macro_lib)]
|
||||||
#![cfg(not(test))]
|
#![cfg(not(test))]
|
||||||
|
|
||||||
extern crate rustc_macro;
|
extern crate proc_macro;
|
||||||
extern crate serde_codegen;
|
extern crate serde_codegen;
|
||||||
|
|
||||||
use rustc_macro::TokenStream;
|
use proc_macro::TokenStream;
|
||||||
|
|
||||||
#[rustc_macro_derive(Serialize)]
|
#[proc_macro_derive(Serialize)]
|
||||||
pub fn derive_serialize(input: TokenStream) -> TokenStream {
|
pub fn derive_serialize(input: TokenStream) -> TokenStream {
|
||||||
let item = format!("#[derive(Serialize)]\n{}", input);
|
let item = format!("#[derive(Serialize)]\n{}", input);
|
||||||
match serde_codegen::expand_single_item(&item) {
|
match serde_codegen::expand_single_item(&item) {
|
||||||
@@ -15,7 +15,7 @@ pub fn derive_serialize(input: TokenStream) -> TokenStream {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[rustc_macro_derive(Deserialize)]
|
#[proc_macro_derive(Deserialize)]
|
||||||
pub fn derive_deserialize(input: TokenStream) -> TokenStream {
|
pub fn derive_deserialize(input: TokenStream) -> TokenStream {
|
||||||
let item = format!("#[derive(Deserialize)]\n{}", input);
|
let item = format!("#[derive(Deserialize)]\n{}", input);
|
||||||
match serde_codegen::expand_single_item(&item) {
|
match serde_codegen::expand_single_item(&item) {
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
#![feature(proc_macro)]
|
||||||
|
|
||||||
|
#[macro_use]
|
||||||
|
extern crate serde_derive;
|
||||||
|
|
||||||
|
#[derive(Serialize)] //~ ERROR: custom derive attribute panicked
|
||||||
|
struct S {
|
||||||
|
#[serde(rename="x", serialize="y")] //~^^ HELP: unknown serde field attribute `serialize`
|
||||||
|
x: (),
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
#![feature(proc_macro)]
|
||||||
|
|
||||||
|
#[macro_use]
|
||||||
|
extern crate serde_derive;
|
||||||
|
|
||||||
|
#[derive(Serialize)] //~ ERROR: custom derive attribute panicked
|
||||||
|
struct S {
|
||||||
|
#[serde(rename="x")]
|
||||||
|
#[serde(rename(deserialize="y"))] //~^^^ HELP: duplicate serde attribute `rename`
|
||||||
|
x: (),
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
#![feature(proc_macro)]
|
||||||
|
|
||||||
|
#[macro_use]
|
||||||
|
extern crate serde_derive;
|
||||||
|
|
||||||
|
#[derive(Serialize)] //~ ERROR: custom derive attribute panicked
|
||||||
|
struct S {
|
||||||
|
#[serde(rename(serialize="x"), rename(serialize="y"))] //~^^ HELP: duplicate serde attribute `rename`
|
||||||
|
x: (),
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
#![feature(proc_macro)]
|
||||||
|
|
||||||
|
#[macro_use]
|
||||||
|
extern crate serde_derive;
|
||||||
|
|
||||||
|
#[derive(Serialize)] //~ ERROR: custom derive attribute panicked
|
||||||
|
struct S {
|
||||||
|
#[serde(rename(serialize="x"))]
|
||||||
|
#[serde(rename="y")] //~^^^ HELP: duplicate serde attribute `rename`
|
||||||
|
x: (),
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
#![feature(proc_macro)]
|
||||||
|
|
||||||
|
#[macro_use]
|
||||||
|
extern crate serde_derive;
|
||||||
|
|
||||||
|
#[derive(Serialize)] //~ ERROR: custom derive attribute panicked
|
||||||
|
struct S {
|
||||||
|
#[serde(rename(serialize="x", serialize="y"))] //~^^ HELP: duplicate serde attribute `rename`
|
||||||
|
x: (),
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
#![feature(proc_macro)]
|
||||||
|
|
||||||
|
#[macro_use]
|
||||||
|
extern crate serde_derive;
|
||||||
|
|
||||||
|
#[derive(Serialize)] //~ ERROR: custom derive attribute panicked
|
||||||
|
struct S {
|
||||||
|
#[serde(rename(serialize="x"))]
|
||||||
|
#[serde(rename(serialize="y"))] //~^^^ HELP: duplicate serde attribute `rename`
|
||||||
|
x: (),
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
#![feature(proc_macro)]
|
||||||
|
|
||||||
|
#[macro_use]
|
||||||
|
extern crate serde_derive;
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize)] //~ ERROR: custom derive attribute panicked
|
||||||
|
struct Test<'a> {
|
||||||
|
s: &'a str, //~^^ HELP: Serde does not support deserializing fields of type &str
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
#![feature(proc_macro)]
|
||||||
|
|
||||||
|
#[macro_use]
|
||||||
|
extern crate serde_derive;
|
||||||
|
|
||||||
|
#[derive(Serialize)] //~ ERROR: custom derive attribute panicked
|
||||||
|
#[serde(abc="xyz")] //~^ HELP: unknown serde container attribute `abc`
|
||||||
|
struct A {
|
||||||
|
x: u32,
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() { }
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
#![feature(proc_macro)]
|
||||||
|
|
||||||
|
#[macro_use]
|
||||||
|
extern crate serde_derive;
|
||||||
|
|
||||||
|
#[derive(Serialize)] //~ ERROR: custom derive attribute panicked
|
||||||
|
struct C {
|
||||||
|
#[serde(abc="xyz")] //~^^ HELP: unknown serde field attribute `abc`
|
||||||
|
x: u32,
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() { }
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
#![feature(proc_macro)]
|
||||||
|
|
||||||
|
#[macro_use]
|
||||||
|
extern crate serde_derive;
|
||||||
|
|
||||||
|
#[derive(Serialize)] //~ ERROR: custom derive attribute panicked
|
||||||
|
enum E {
|
||||||
|
#[serde(abc="xyz")] //~^^ HELP: unknown serde variant attribute `abc`
|
||||||
|
V,
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() { }
|
||||||
+4
-3
@@ -1,8 +1,9 @@
|
|||||||
#![feature(custom_derive, plugin)]
|
#![feature(proc_macro)]
|
||||||
#![plugin(serde_macros, clippy)]
|
|
||||||
|
|
||||||
#![deny(identity_op)]
|
#![deny(identity_op)]
|
||||||
|
|
||||||
|
#[macro_use]
|
||||||
|
extern crate serde_derive;
|
||||||
|
|
||||||
// The derived implementation uses 0+1 to add up the number of fields
|
// The derived implementation uses 0+1 to add up the number of fields
|
||||||
// serialized, which Clippy warns about. If the expansion info is registered
|
// serialized, which Clippy warns about. If the expansion info is registered
|
||||||
// correctly, the Clippy lint is not triggered.
|
// correctly, the Clippy lint is not triggered.
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
#![feature(test, rustc_macro, rustc_attrs)]
|
#![feature(test, proc_macro)]
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate serde_derive;
|
extern crate serde_derive;
|
||||||
@@ -6,3 +6,5 @@ extern crate serde_derive;
|
|||||||
extern crate test;
|
extern crate test;
|
||||||
|
|
||||||
include!("../../testing/tests/test.rs.in");
|
include!("../../testing/tests/test.rs.in");
|
||||||
|
|
||||||
|
mod compile_tests;
|
||||||
|
|||||||
@@ -1,2 +0,0 @@
|
|||||||
# To prevent compiletest from seeing two versions of serde
|
|
||||||
paths = ["../serde"]
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
/target
|
|
||||||
/Cargo.lock
|
|
||||||
@@ -1,41 +0,0 @@
|
|||||||
[package]
|
|
||||||
name = "serde_macros"
|
|
||||||
version = "0.8.9"
|
|
||||||
authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>"]
|
|
||||||
license = "MIT/Apache-2.0"
|
|
||||||
description = "Macros to auto-generate implementations for the serde framework"
|
|
||||||
homepage = "https://serde.rs"
|
|
||||||
repository = "https://github.com/serde-rs/serde"
|
|
||||||
documentation = "https://serde.rs/codegen.html"
|
|
||||||
keywords = ["serde", "serialization"]
|
|
||||||
include = ["Cargo.toml", "src/**/*.rs"]
|
|
||||||
|
|
||||||
[lib]
|
|
||||||
name = "serde_macros"
|
|
||||||
plugin = true
|
|
||||||
|
|
||||||
[features]
|
|
||||||
unstable-testing = [
|
|
||||||
"clippy",
|
|
||||||
"serde/unstable-testing",
|
|
||||||
"serde_codegen/unstable-testing"
|
|
||||||
]
|
|
||||||
|
|
||||||
[dependencies]
|
|
||||||
clippy = { version = "^0.*", optional = true }
|
|
||||||
serde_codegen = { version = "=0.8.9", default-features = false, features = ["unstable"], path = "../serde_codegen" }
|
|
||||||
|
|
||||||
[dev-dependencies]
|
|
||||||
compiletest_rs = "^0.2.0"
|
|
||||||
fnv = "1.0"
|
|
||||||
rustc-serialize = "^0.3.16"
|
|
||||||
serde = { version = "0.8.9", path = "../serde" }
|
|
||||||
serde_test = { version = "0.8.9", path = "../serde_test" }
|
|
||||||
|
|
||||||
[[test]]
|
|
||||||
name = "test"
|
|
||||||
path = "tests/test.rs"
|
|
||||||
|
|
||||||
[[bench]]
|
|
||||||
name = "bench"
|
|
||||||
path = "benches/bench.rs"
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
#![feature(custom_attribute, custom_derive, plugin, test)]
|
|
||||||
#![cfg_attr(feature = "clippy", plugin(clippy))]
|
|
||||||
#![plugin(serde_macros)]
|
|
||||||
|
|
||||||
extern crate rustc_serialize;
|
|
||||||
extern crate serde;
|
|
||||||
extern crate test;
|
|
||||||
|
|
||||||
include!("../../testing/benches/bench.rs.in");
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
#![feature(plugin_registrar, rustc_private)]
|
|
||||||
#![cfg_attr(feature = "clippy", feature(plugin))]
|
|
||||||
#![cfg_attr(feature = "clippy", plugin(clippy))]
|
|
||||||
|
|
||||||
extern crate serde_codegen;
|
|
||||||
extern crate rustc_plugin;
|
|
||||||
|
|
||||||
#[plugin_registrar]
|
|
||||||
#[doc(hidden)]
|
|
||||||
pub fn plugin_registrar(reg: &mut rustc_plugin::Registry) {
|
|
||||||
serde_codegen::register(reg);
|
|
||||||
}
|
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
#![feature(custom_attribute, custom_derive, plugin)]
|
|
||||||
#![plugin(serde_macros)]
|
|
||||||
|
|
||||||
#[derive(Serialize)] //~ ERROR: 6 errors:
|
|
||||||
struct S {
|
|
||||||
#[serde(rename(serialize="x"))]
|
|
||||||
#[serde(rename(serialize="y"))] // ERROR: duplicate serde attribute `rename`
|
|
||||||
a: (),
|
|
||||||
|
|
||||||
#[serde(rename(serialize="x"))]
|
|
||||||
#[serde(rename="y")] // ERROR: duplicate serde attribute `rename`
|
|
||||||
b: (),
|
|
||||||
|
|
||||||
#[serde(rename(serialize="x"))]
|
|
||||||
#[serde(rename(deserialize="y"))] // ok
|
|
||||||
c: (),
|
|
||||||
|
|
||||||
#[serde(rename="x")]
|
|
||||||
#[serde(rename(deserialize="y"))] // ERROR: duplicate serde attribute `rename`
|
|
||||||
d: (),
|
|
||||||
|
|
||||||
#[serde(rename(serialize="x", serialize="y"))] // ERROR: duplicate serde attribute `rename`
|
|
||||||
e: (),
|
|
||||||
|
|
||||||
#[serde(rename="x", serialize="y")] // ERROR: unknown serde field attribute `serialize`
|
|
||||||
f: (),
|
|
||||||
|
|
||||||
#[serde(rename(serialize="x"), rename(serialize="y"))] // ERROR: duplicate serde attribute `rename`
|
|
||||||
g: (),
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {}
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
#![feature(custom_attribute, custom_derive, plugin)]
|
|
||||||
#![plugin(serde_macros)]
|
|
||||||
|
|
||||||
extern crate serde;
|
|
||||||
|
|
||||||
#[derive(Serialize)] //~ unknown serde container attribute `abc`
|
|
||||||
#[serde(abc="xyz")]
|
|
||||||
struct A {
|
|
||||||
x: u32,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Deserialize)] //~ unknown serde container attribute `abc`
|
|
||||||
#[serde(abc="xyz")]
|
|
||||||
struct B {
|
|
||||||
x: u32,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Serialize)] //~ unknown serde field attribute `abc`
|
|
||||||
struct C {
|
|
||||||
#[serde(abc="xyz")]
|
|
||||||
x: u32,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Deserialize)] //~ unknown serde field attribute `abc`
|
|
||||||
struct D {
|
|
||||||
#[serde(abc="xyz")]
|
|
||||||
x: u32,
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() { }
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
#![feature(custom_attribute, custom_derive, plugin)]
|
|
||||||
#![plugin(serde_macros)]
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)] //~ ERROR: Serde does not support deserializing fields of type &str
|
|
||||||
struct Test<'a> {
|
|
||||||
s: &'a str,
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {}
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
#![feature(test, custom_attribute, custom_derive, plugin)]
|
|
||||||
#![plugin(serde_macros)]
|
|
||||||
|
|
||||||
extern crate test;
|
|
||||||
|
|
||||||
include!("../../testing/tests/test.rs.in");
|
|
||||||
|
|
||||||
mod compile_tests;
|
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "serde_test"
|
name = "serde_test"
|
||||||
version = "0.8.10"
|
version = "0.8.12"
|
||||||
authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>"]
|
authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>"]
|
||||||
license = "MIT/Apache-2.0"
|
license = "MIT/Apache-2.0"
|
||||||
description = "Token De/Serializer for testing De/Serialize implementations"
|
description = "Token De/Serializer for testing De/Serialize implementations"
|
||||||
@@ -12,4 +12,4 @@ keywords = ["serde", "serialization"]
|
|||||||
include = ["Cargo.toml", "src/**/*.rs"]
|
include = ["Cargo.toml", "src/**/*.rs"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
serde = { version = "0.8.10", path = "../serde" }
|
serde = { version = "0.8.12", path = "../serde" }
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "serde_testing"
|
name = "serde_testing"
|
||||||
version = "0.8.10"
|
version = "0.8.12"
|
||||||
authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>"]
|
authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>"]
|
||||||
license = "MIT/Apache-2.0"
|
license = "MIT/Apache-2.0"
|
||||||
description = "A generic serialization/deserialization framework"
|
description = "A generic serialization/deserialization framework"
|
||||||
|
|||||||
Reference in New Issue
Block a user