mirror of
https://github.com/pezkuwichain/serde.git
synced 2026-04-23 08:18:03 +00:00
Compare commits
17 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 1b42f3f594 | |||
| cafa02d9b4 | |||
| 1d719b542c | |||
| 532b950971 | |||
| f93b4e91e6 | |||
| 94e2ccc94e | |||
| cbe6b4c97c | |||
| a46a4e27dd | |||
| 4919a3184d | |||
| 0b19608d85 | |||
| 99bddddd8e | |||
| 85c95040b3 | |||
| 339c0f5493 | |||
| b4d5c26f4e | |||
| f4e1ffa2cb | |||
| ef5d09e144 | |||
| e547a06639 |
+3
-3
@@ -1,11 +1,11 @@
|
||||
sudo: false
|
||||
language: rust
|
||||
rust:
|
||||
- 1.10.0
|
||||
- 1.11.0
|
||||
- stable
|
||||
- nightly
|
||||
- 1.8.0
|
||||
- 1.9.0
|
||||
- beta
|
||||
- nightly
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
|
||||
@@ -15,7 +15,7 @@ You may be looking for:
|
||||
## Serde in action
|
||||
|
||||
```rust
|
||||
#![feature(rustc_macro)]
|
||||
#![feature(proc_macro)]
|
||||
|
||||
#[macro_use]
|
||||
extern crate serde_derive;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#![cfg_attr(feature = "serde_derive", feature(rustc_macro))]
|
||||
#![cfg_attr(feature = "serde_derive", feature(proc_macro))]
|
||||
|
||||
#[cfg(feature = "serde_derive")]
|
||||
#[macro_use]
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "serde"
|
||||
version = "0.8.11"
|
||||
version = "0.8.14"
|
||||
authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>"]
|
||||
license = "MIT/Apache-2.0"
|
||||
description = "A generic serialization/deserialization framework"
|
||||
|
||||
+69
-98
@@ -512,27 +512,26 @@ seq_impl!(
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
struct ArrayVisitor0<T> {
|
||||
marker: PhantomData<T>,
|
||||
struct ArrayVisitor<A> {
|
||||
marker: PhantomData<A>,
|
||||
}
|
||||
|
||||
impl<T> ArrayVisitor0<T> {
|
||||
/// Construct a `ArrayVisitor0<T>`.
|
||||
impl<A> ArrayVisitor<A> {
|
||||
pub fn new() -> Self {
|
||||
ArrayVisitor0 {
|
||||
ArrayVisitor {
|
||||
marker: PhantomData,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Visitor for ArrayVisitor0<T> where T: Deserialize + Default {
|
||||
impl<T> Visitor for ArrayVisitor<[T; 0]> where T: Deserialize {
|
||||
type Value = [T; 0];
|
||||
|
||||
#[inline]
|
||||
fn visit_unit<E>(&mut self) -> Result<[T; 0], E>
|
||||
where E: Error,
|
||||
{
|
||||
Ok([T::default(); 0])
|
||||
Ok([])
|
||||
}
|
||||
|
||||
#[inline]
|
||||
@@ -540,37 +539,24 @@ impl<T> Visitor for ArrayVisitor0<T> where T: Deserialize + Default {
|
||||
where V: SeqVisitor,
|
||||
{
|
||||
try!(visitor.end());
|
||||
Ok([T::default(); 0])
|
||||
Ok([])
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Deserialize for [T; 0]
|
||||
where T: Deserialize + Default
|
||||
where T: Deserialize
|
||||
{
|
||||
fn deserialize<D>(deserializer: &mut D) -> Result<[T; 0], D::Error>
|
||||
where D: Deserializer,
|
||||
{
|
||||
deserializer.deserialize_seq(ArrayVisitor0::new())
|
||||
deserializer.deserialize_seq_fixed_size(0, ArrayVisitor::<[T; 0]>::new())
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! array_impls {
|
||||
($($visitor:ident, $len:expr => ($($name:ident),+),)+) => {
|
||||
($($len:expr => ($($name:ident)+))+) => {
|
||||
$(
|
||||
struct $visitor<T> {
|
||||
marker: PhantomData<T>,
|
||||
}
|
||||
|
||||
impl<T> $visitor<T> {
|
||||
/// Construct a `ArrayVisitor*<T>`.
|
||||
pub fn new() -> Self {
|
||||
$visitor {
|
||||
marker: PhantomData
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Visitor for $visitor<T> where T: Deserialize {
|
||||
impl<T> Visitor for ArrayVisitor<[T; $len]> where T: Deserialize {
|
||||
type Value = [T; $len];
|
||||
|
||||
#[inline]
|
||||
@@ -580,13 +566,13 @@ macro_rules! array_impls {
|
||||
$(
|
||||
let $name = match try!(visitor.visit()) {
|
||||
Some(val) => val,
|
||||
None => { return Err(Error::end_of_stream()); }
|
||||
None => return Err(Error::end_of_stream()),
|
||||
};
|
||||
)+;
|
||||
)+
|
||||
|
||||
try!(visitor.end());
|
||||
|
||||
Ok([$($name,)+])
|
||||
Ok([$($name),+])
|
||||
}
|
||||
}
|
||||
|
||||
@@ -596,7 +582,7 @@ macro_rules! array_impls {
|
||||
fn deserialize<D>(deserializer: &mut D) -> Result<[T; $len], D::Error>
|
||||
where D: Deserializer,
|
||||
{
|
||||
deserializer.deserialize_seq_fixed_size($len, $visitor::new())
|
||||
deserializer.deserialize_seq_fixed_size($len, ArrayVisitor::<[T; $len]>::new())
|
||||
}
|
||||
}
|
||||
)+
|
||||
@@ -604,71 +590,58 @@ macro_rules! array_impls {
|
||||
}
|
||||
|
||||
array_impls! {
|
||||
ArrayVisitor1, 1 => (a),
|
||||
ArrayVisitor2, 2 => (a, b),
|
||||
ArrayVisitor3, 3 => (a, b, c),
|
||||
ArrayVisitor4, 4 => (a, b, c, d),
|
||||
ArrayVisitor5, 5 => (a, b, c, d, e),
|
||||
ArrayVisitor6, 6 => (a, b, c, d, e, f),
|
||||
ArrayVisitor7, 7 => (a, b, c, d, e, f, g),
|
||||
ArrayVisitor8, 8 => (a, b, c, d, e, f, g, h),
|
||||
ArrayVisitor9, 9 => (a, b, c, d, e, f, g, h, i),
|
||||
ArrayVisitor10, 10 => (a, b, c, d, e, f, g, h, i, j),
|
||||
ArrayVisitor11, 11 => (a, b, c, d, e, f, g, h, i, j, k),
|
||||
ArrayVisitor12, 12 => (a, b, c, d, e, f, g, h, i, j, k, l),
|
||||
ArrayVisitor13, 13 => (a, b, c, d, e, f, g, h, i, j, k, l, m),
|
||||
ArrayVisitor14, 14 => (a, b, c, d, e, f, g, h, i, j, k, l, m, n),
|
||||
ArrayVisitor15, 15 => (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o),
|
||||
ArrayVisitor16, 16 => (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p),
|
||||
ArrayVisitor17, 17 => (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q),
|
||||
ArrayVisitor18, 18 => (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r),
|
||||
ArrayVisitor19, 19 => (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s),
|
||||
ArrayVisitor20, 20 => (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s ,t),
|
||||
ArrayVisitor21, 21 => (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u),
|
||||
ArrayVisitor22, 22 => (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v),
|
||||
ArrayVisitor23, 23 => (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w),
|
||||
ArrayVisitor24, 24 => (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x),
|
||||
ArrayVisitor25, 25 => (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x,
|
||||
y),
|
||||
ArrayVisitor26, 26 => (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x,
|
||||
y, z),
|
||||
ArrayVisitor27, 27 => (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x,
|
||||
y, z, aa),
|
||||
ArrayVisitor28, 28 => (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x,
|
||||
y, z, aa, ab),
|
||||
ArrayVisitor29, 29 => (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x,
|
||||
y, z, aa, ab, ac),
|
||||
ArrayVisitor30, 30 => (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x,
|
||||
y, z, aa, ab, ac, ad),
|
||||
ArrayVisitor31, 31 => (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x,
|
||||
y, z, aa, ab, ac, ad, ae),
|
||||
ArrayVisitor32, 32 => (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x,
|
||||
y, z, aa, ab, ac, ad, ae, af),
|
||||
1 => (a)
|
||||
2 => (a b)
|
||||
3 => (a b c)
|
||||
4 => (a b c d)
|
||||
5 => (a b c d e)
|
||||
6 => (a b c d e f)
|
||||
7 => (a b c d e f g)
|
||||
8 => (a b c d e f g h)
|
||||
9 => (a b c d e f g h i)
|
||||
10 => (a b c d e f g h i j)
|
||||
11 => (a b c d e f g h i j k)
|
||||
12 => (a b c d e f g h i j k l)
|
||||
13 => (a b c d e f g h i j k l m)
|
||||
14 => (a b c d e f g h i j k l m n)
|
||||
15 => (a b c d e f g h i j k l m n o)
|
||||
16 => (a b c d e f g h i j k l m n o p)
|
||||
17 => (a b c d e f g h i j k l m n o p q)
|
||||
18 => (a b c d e f g h i j k l m n o p q r)
|
||||
19 => (a b c d e f g h i j k l m n o p q r s)
|
||||
20 => (a b c d e f g h i j k l m n o p q r s t)
|
||||
21 => (a b c d e f g h i j k l m n o p q r s t u)
|
||||
22 => (a b c d e f g h i j k l m n o p q r s t u v)
|
||||
23 => (a b c d e f g h i j k l m n o p q r s t u v w)
|
||||
24 => (a b c d e f g h i j k l m n o p q r s t u v w x)
|
||||
25 => (a b c d e f g h i j k l m n o p q r s t u v w x y)
|
||||
26 => (a b c d e f g h i j k l m n o p q r s t u v w x y z)
|
||||
27 => (a b c d e f g h i j k l m n o p q r s t u v w x y z aa)
|
||||
28 => (a b c d e f g h i j k l m n o p q r s t u v w x y z aa ab)
|
||||
29 => (a b c d e f g h i j k l m n o p q r s t u v w x y z aa ab ac)
|
||||
30 => (a b c d e f g h i j k l m n o p q r s t u v w x y z aa ab ac ad)
|
||||
31 => (a b c d e f g h i j k l m n o p q r s t u v w x y z aa ab ac ad ae)
|
||||
32 => (a b c d e f g h i j k l m n o p q r s t u v w x y z aa ab ac ad ae af)
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
macro_rules! tuple_impls {
|
||||
($($len:expr => $visitor:ident => ($($name:ident),+),)+) => {
|
||||
($($len:expr => $visitor:ident => ($($name:ident)+))+) => {
|
||||
$(
|
||||
/// Construct a tuple visitor.
|
||||
pub struct $visitor<$($name,)+> {
|
||||
marker: PhantomData<($($name,)+)>,
|
||||
}
|
||||
|
||||
impl<
|
||||
$($name: Deserialize,)+
|
||||
> $visitor<$($name,)+> {
|
||||
impl<$($name: Deserialize,)+> $visitor<$($name,)+> {
|
||||
/// Construct a `TupleVisitor*<T>`.
|
||||
pub fn new() -> Self {
|
||||
$visitor { marker: PhantomData }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
impl<
|
||||
$($name: Deserialize,)+
|
||||
> Visitor for $visitor<$($name,)+> {
|
||||
impl<$($name: Deserialize),+> Visitor for $visitor<$($name,)+> {
|
||||
type Value = ($($name,)+);
|
||||
|
||||
#[inline]
|
||||
@@ -679,9 +652,9 @@ macro_rules! tuple_impls {
|
||||
$(
|
||||
let $name = match try!(visitor.visit()) {
|
||||
Some(value) => value,
|
||||
None => { return Err(Error::end_of_stream()); }
|
||||
None => return Err(Error::end_of_stream()),
|
||||
};
|
||||
)+;
|
||||
)+
|
||||
|
||||
try!(visitor.end());
|
||||
|
||||
@@ -689,9 +662,7 @@ macro_rules! tuple_impls {
|
||||
}
|
||||
}
|
||||
|
||||
impl<
|
||||
$($name: Deserialize),+
|
||||
> Deserialize for ($($name,)+) {
|
||||
impl<$($name: Deserialize),+> Deserialize for ($($name,)+) {
|
||||
#[inline]
|
||||
fn deserialize<D>(deserializer: &mut D) -> Result<($($name,)+), D::Error>
|
||||
where D: Deserializer,
|
||||
@@ -704,22 +675,22 @@ macro_rules! tuple_impls {
|
||||
}
|
||||
|
||||
tuple_impls! {
|
||||
1 => TupleVisitor1 => (T0),
|
||||
2 => TupleVisitor2 => (T0, T1),
|
||||
3 => TupleVisitor3 => (T0, T1, T2),
|
||||
4 => TupleVisitor4 => (T0, T1, T2, T3),
|
||||
5 => TupleVisitor5 => (T0, T1, T2, T3, T4),
|
||||
6 => TupleVisitor6 => (T0, T1, T2, T3, T4, T5),
|
||||
7 => TupleVisitor7 => (T0, T1, T2, T3, T4, T5, T6),
|
||||
8 => TupleVisitor8 => (T0, T1, T2, T3, T4, T5, T6, T7),
|
||||
9 => TupleVisitor9 => (T0, T1, T2, T3, T4, T5, T6, T7, T8),
|
||||
10 => TupleVisitor10 => (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9),
|
||||
11 => TupleVisitor11 => (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10),
|
||||
12 => TupleVisitor12 => (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11),
|
||||
13 => TupleVisitor13 => (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12),
|
||||
14 => TupleVisitor14 => (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13),
|
||||
15 => TupleVisitor15 => (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14),
|
||||
16 => TupleVisitor16 => (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15),
|
||||
1 => TupleVisitor1 => (T0)
|
||||
2 => TupleVisitor2 => (T0 T1)
|
||||
3 => TupleVisitor3 => (T0 T1 T2)
|
||||
4 => TupleVisitor4 => (T0 T1 T2 T3)
|
||||
5 => TupleVisitor5 => (T0 T1 T2 T3 T4)
|
||||
6 => TupleVisitor6 => (T0 T1 T2 T3 T4 T5)
|
||||
7 => TupleVisitor7 => (T0 T1 T2 T3 T4 T5 T6)
|
||||
8 => TupleVisitor8 => (T0 T1 T2 T3 T4 T5 T6 T7)
|
||||
9 => TupleVisitor9 => (T0 T1 T2 T3 T4 T5 T6 T7 T8)
|
||||
10 => TupleVisitor10 => (T0 T1 T2 T3 T4 T5 T6 T7 T8 T9)
|
||||
11 => TupleVisitor11 => (T0 T1 T2 T3 T4 T5 T6 T7 T8 T9 T10)
|
||||
12 => TupleVisitor12 => (T0 T1 T2 T3 T4 T5 T6 T7 T8 T9 T10 T11)
|
||||
13 => TupleVisitor13 => (T0 T1 T2 T3 T4 T5 T6 T7 T8 T9 T10 T11 T12)
|
||||
14 => TupleVisitor14 => (T0 T1 T2 T3 T4 T5 T6 T7 T8 T9 T10 T11 T12 T13)
|
||||
15 => TupleVisitor15 => (T0 T1 T2 T3 T4 T5 T6 T7 T8 T9 T10 T11 T12 T13 T14)
|
||||
16 => TupleVisitor16 => (T0 T1 T2 T3 T4 T5 T6 T7 T8 T9 T10 T11 T12 T13 T14 T15)
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "serde_codegen"
|
||||
version = "0.8.11"
|
||||
version = "0.8.14"
|
||||
authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>"]
|
||||
license = "MIT/Apache-2.0"
|
||||
description = "Macros to auto-generate implementations for the serde framework"
|
||||
@@ -22,8 +22,8 @@ with-syn = []
|
||||
|
||||
[dependencies]
|
||||
clippy = { version = "^0.*", optional = true }
|
||||
quote = "0.2"
|
||||
serde_codegen_internals = { version = "=0.9.0", default-features = false, path = "../serde_codegen_internals" }
|
||||
syn = { version = "0.8", features = ["aster", "visit"] }
|
||||
syntex = { version = "^0.44.0", optional = true }
|
||||
syntex_syntax = { version = "^0.44.0", optional = true }
|
||||
quote = "0.3"
|
||||
serde_codegen_internals = { version = "=0.10.0", default-features = false, path = "../serde_codegen_internals" }
|
||||
syn = { version = "0.9", features = ["aster", "visit"] }
|
||||
syntex = { version = "^0.45.0", optional = true }
|
||||
syntex_syntax = { version = "^0.45.0", optional = true }
|
||||
|
||||
+20
-27
@@ -185,17 +185,17 @@ fn deserialize_visitor(generics: &syn::Generics) -> (Tokens, Tokens, Tokens) {
|
||||
let ty_param_idents = if ty_param_idents.is_empty() {
|
||||
None
|
||||
} else {
|
||||
Some(quote!(::<#(ty_param_idents),*>))
|
||||
Some(quote!(::<#(#ty_param_idents),*>))
|
||||
};
|
||||
|
||||
let phantom_exprs = iter::repeat(quote!(::std::marker::PhantomData)).take(num_phantoms);
|
||||
|
||||
(
|
||||
quote! {
|
||||
struct __Visitor #generics ( #(phantom_types),* ) #where_clause;
|
||||
struct __Visitor #generics ( #(#phantom_types),* ) #where_clause;
|
||||
},
|
||||
quote!(__Visitor <#(all_params),*> ),
|
||||
quote!(__Visitor #ty_param_idents ( #(phantom_exprs),* )),
|
||||
quote!(__Visitor <#(#all_params),*> ),
|
||||
quote!(__Visitor #ty_param_idents ( #(#phantom_exprs),* )),
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -358,17 +358,17 @@ fn deserialize_seq(
|
||||
quote!(#ident: #value)
|
||||
});
|
||||
quote! {
|
||||
#type_path { #(args),* }
|
||||
#type_path { #(#args),* }
|
||||
}
|
||||
} else {
|
||||
let args = (0..fields.len()).map(|i| aster::id(format!("__field{}", i)));
|
||||
quote! {
|
||||
#type_path ( #(args),* )
|
||||
#type_path ( #(#args),* )
|
||||
}
|
||||
};
|
||||
|
||||
quote! {
|
||||
#(let_values)*
|
||||
#(#let_values)*
|
||||
|
||||
try!(visitor.end());
|
||||
|
||||
@@ -505,7 +505,7 @@ fn deserialize_item_enum(
|
||||
let variant_names = variants.iter().map(|variant| variant.ident.to_string());
|
||||
|
||||
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() {
|
||||
@@ -551,7 +551,7 @@ fn deserialize_item_enum(
|
||||
where __V: _serde::de::VariantVisitor,
|
||||
{
|
||||
match try!(visitor.visit_variant()) {
|
||||
#(variant_arms)*
|
||||
#(#variant_arms)*
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -678,7 +678,7 @@ fn deserialize_field_visitor(
|
||||
|
||||
let index_body = quote! {
|
||||
match value {
|
||||
#(index_field_arms)*
|
||||
#(#index_field_arms)*
|
||||
_ => #fallthrough_index_arm_expr
|
||||
}
|
||||
};
|
||||
@@ -704,7 +704,7 @@ fn deserialize_field_visitor(
|
||||
|
||||
let str_body = quote! {
|
||||
match value {
|
||||
#(str_field_arms)*
|
||||
#(#str_field_arms)*
|
||||
_ => #fallthrough_str_arm_expr
|
||||
}
|
||||
};
|
||||
@@ -732,20 +732,18 @@ fn deserialize_field_visitor(
|
||||
|
||||
let bytes_body = quote! {
|
||||
match value {
|
||||
#(bytes_field_arms)*
|
||||
#(#bytes_field_arms)*
|
||||
_ => #fallthrough_bytes_arm_expr
|
||||
}
|
||||
};
|
||||
|
||||
let field_enum = quote! {
|
||||
quote! {
|
||||
#[allow(non_camel_case_types)]
|
||||
enum __Field {
|
||||
#(field_idents,)*
|
||||
#(#field_idents,)*
|
||||
#ignore_variant
|
||||
}
|
||||
};
|
||||
|
||||
let impl_item = quote! {
|
||||
impl _serde::de::Deserialize for __Field {
|
||||
#[inline]
|
||||
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)
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
quote! {
|
||||
#field_enum
|
||||
#impl_item
|
||||
}
|
||||
}
|
||||
|
||||
@@ -816,7 +809,7 @@ fn deserialize_struct_visitor(
|
||||
});
|
||||
|
||||
let fields_stmt = quote! {
|
||||
const FIELDS: &'static [&'static str] = &[ #(field_names),* ];
|
||||
const FIELDS: &'static [&'static str] = &[ #(#field_names),* ];
|
||||
};
|
||||
|
||||
(field_visitor, fields_stmt, visit_map)
|
||||
@@ -929,21 +922,21 @@ fn deserialize_map(
|
||||
});
|
||||
|
||||
quote! {
|
||||
#(let_values)*
|
||||
#(#let_values)*
|
||||
|
||||
while let Some(key) = try!(visitor.visit_key::<__Field>()) {
|
||||
match key {
|
||||
#(value_arms)*
|
||||
#(skipped_arms)*
|
||||
#(#value_arms)*
|
||||
#(#skipped_arms)*
|
||||
#ignored_arm
|
||||
}
|
||||
}
|
||||
|
||||
try!(visitor.end());
|
||||
|
||||
#(extract_values)*
|
||||
#(#extract_values)*
|
||||
|
||||
Ok(#struct_path { #(result),* })
|
||||
Ok(#struct_path { #(#result),* })
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -169,8 +169,8 @@ macro_rules! shim {
|
||||
use syntax::parse;
|
||||
let name = stringify!($name).to_string();
|
||||
let cfg = Vec::new();
|
||||
let sess = parse::ParseSess::new();
|
||||
let impl_item = parse::parse_item_from_source_str(name, expanded, cfg, &sess);
|
||||
let sess = cx.parse_sess;
|
||||
let impl_item = parse::parse_item_from_source_str(name, expanded, cfg, sess);
|
||||
push(::syntax::ext::base::Annotatable::Item(impl_item.unwrap().unwrap()));
|
||||
}
|
||||
};
|
||||
@@ -201,7 +201,7 @@ pub fn expand_single_item(item: &str) -> Result<String, String> {
|
||||
let mut de = false;
|
||||
let item = syn::MacroInput {
|
||||
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);
|
||||
}
|
||||
let (name, nested) = match attr.value {
|
||||
@@ -210,6 +210,7 @@ pub fn expand_single_item(item: &str) -> Result<String, String> {
|
||||
};
|
||||
if name != "derive" {
|
||||
return Some(syn::Attribute {
|
||||
style: syn::AttrStyle::Outer,
|
||||
value: syn::MetaItem::List(name, nested),
|
||||
is_sugared_doc: false,
|
||||
});
|
||||
@@ -231,6 +232,7 @@ pub fn expand_single_item(item: &str) -> Result<String, String> {
|
||||
None
|
||||
} else {
|
||||
Some(syn::Attribute {
|
||||
style: syn::AttrStyle::Outer,
|
||||
value: syn::MetaItem::List(name, rest),
|
||||
is_sugared_doc: false,
|
||||
})
|
||||
|
||||
@@ -168,7 +168,7 @@ fn serialize_tuple_struct(
|
||||
|
||||
quote! {
|
||||
let #let_mut __serde_state = try!(_serializer.serialize_tuple_struct(#type_name, #len));
|
||||
#(serialize_stmts)*
|
||||
#(#serialize_stmts)*
|
||||
_serializer.serialize_tuple_struct_end(__serde_state)
|
||||
}
|
||||
}
|
||||
@@ -209,7 +209,7 @@ fn serialize_struct(
|
||||
|
||||
quote! {
|
||||
let #let_mut __serde_state = try!(_serializer.serialize_struct(#type_name, #len));
|
||||
#(serialize_fields)*
|
||||
#(#serialize_fields)*
|
||||
_serializer.serialize_struct_end(__serde_state)
|
||||
}
|
||||
}
|
||||
@@ -238,7 +238,7 @@ fn serialize_item_enum(
|
||||
|
||||
quote! {
|
||||
match *self {
|
||||
#(arms)*
|
||||
#(#arms)*
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -290,7 +290,7 @@ fn serialize_variant(
|
||||
})
|
||||
.collect();
|
||||
|
||||
let pat = quote!(#type_ident::#variant_ident(#(field_names),*));
|
||||
let pat = quote!(#type_ident::#variant_ident(#(#field_names),*));
|
||||
|
||||
let block = serialize_tuple_variant(
|
||||
type_name,
|
||||
@@ -313,7 +313,7 @@ fn serialize_variant(
|
||||
};
|
||||
quote!(ref #id)
|
||||
});
|
||||
let pat = quote!(#type_ident::#variant_ident { #(fields),* });
|
||||
let pat = quote!(#type_ident::#variant_ident { #(#fields),* });
|
||||
|
||||
let block = serialize_struct_variant(
|
||||
variant_index,
|
||||
@@ -381,7 +381,7 @@ fn serialize_tuple_variant(
|
||||
#variant_index,
|
||||
#variant_name,
|
||||
#len));
|
||||
#(serialize_stmts)*
|
||||
#(#serialize_stmts)*
|
||||
_serializer.serialize_tuple_variant_end(__serde_state)
|
||||
}
|
||||
}
|
||||
@@ -428,7 +428,7 @@ fn serialize_struct_variant(
|
||||
#variant_name,
|
||||
#len,
|
||||
));
|
||||
#(serialize_fields)*
|
||||
#(#serialize_fields)*
|
||||
_serializer.serialize_struct_variant_end(__serde_state)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "serde_codegen_internals"
|
||||
version = "0.9.0"
|
||||
version = "0.10.0"
|
||||
authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>"]
|
||||
license = "MIT/Apache-2.0"
|
||||
description = "AST representation used by Serde codegen. Unstable."
|
||||
@@ -15,4 +15,4 @@ unstable-testing = ["clippy"]
|
||||
|
||||
[dependencies]
|
||||
clippy = { version = "^0.*", optional = true }
|
||||
syn = "0.8"
|
||||
syn = "0.9"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "serde_derive"
|
||||
version = "0.8.11"
|
||||
version = "0.8.14"
|
||||
authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>"]
|
||||
license = "MIT/Apache-2.0"
|
||||
description = "Macros 1.1 implementation of #[derive(Serialize, Deserialize)]"
|
||||
@@ -12,10 +12,10 @@ include = ["Cargo.toml", "src/**/*.rs"]
|
||||
|
||||
[lib]
|
||||
name = "serde_derive"
|
||||
rustc-macro = true
|
||||
proc-macro = true
|
||||
|
||||
[dependencies.serde_codegen]
|
||||
version = "=0.8.11"
|
||||
version = "=0.8.14"
|
||||
path = "../serde_codegen"
|
||||
default-features = false
|
||||
features = ["with-syn"]
|
||||
@@ -23,5 +23,5 @@ features = ["with-syn"]
|
||||
[dev-dependencies]
|
||||
compiletest_rs = "^0.2.0"
|
||||
fnv = "1.0"
|
||||
serde = { version = "0.8.11", path = "../serde" }
|
||||
serde_test = { version = "0.8.11", path = "../serde_test" }
|
||||
serde = { version = "0.8.14", path = "../serde" }
|
||||
serde_test = { version = "0.8.14", path = "../serde_test" }
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
#![feature(rustc_macro, rustc_macro_lib)]
|
||||
#![feature(proc_macro, proc_macro_lib)]
|
||||
#![cfg(not(test))]
|
||||
|
||||
extern crate rustc_macro;
|
||||
extern crate proc_macro;
|
||||
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 {
|
||||
let item = format!("#[derive(Serialize)]\n{}", input);
|
||||
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 {
|
||||
let item = format!("#[derive(Deserialize)]\n{}", input);
|
||||
match serde_codegen::expand_single_item(&item) {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#![feature(rustc_macro)]
|
||||
#![feature(proc_macro)]
|
||||
|
||||
#[macro_use]
|
||||
extern crate serde_derive;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#![feature(rustc_macro)]
|
||||
#![feature(proc_macro)]
|
||||
|
||||
#[macro_use]
|
||||
extern crate serde_derive;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#![feature(rustc_macro)]
|
||||
#![feature(proc_macro)]
|
||||
|
||||
#[macro_use]
|
||||
extern crate serde_derive;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#![feature(rustc_macro)]
|
||||
#![feature(proc_macro)]
|
||||
|
||||
#[macro_use]
|
||||
extern crate serde_derive;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#![feature(rustc_macro)]
|
||||
#![feature(proc_macro)]
|
||||
|
||||
#[macro_use]
|
||||
extern crate serde_derive;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#![feature(rustc_macro)]
|
||||
#![feature(proc_macro)]
|
||||
|
||||
#[macro_use]
|
||||
extern crate serde_derive;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#![feature(rustc_macro)]
|
||||
#![feature(proc_macro)]
|
||||
|
||||
#[macro_use]
|
||||
extern crate serde_derive;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#![feature(rustc_macro)]
|
||||
#![feature(proc_macro)]
|
||||
|
||||
#[macro_use]
|
||||
extern crate serde_derive;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#![feature(rustc_macro)]
|
||||
#![feature(proc_macro)]
|
||||
|
||||
#[macro_use]
|
||||
extern crate serde_derive;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#![feature(rustc_macro)]
|
||||
#![feature(proc_macro)]
|
||||
|
||||
#[macro_use]
|
||||
extern crate serde_derive;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#![feature(rustc_macro)]
|
||||
#![feature(proc_macro)]
|
||||
#![deny(identity_op)]
|
||||
|
||||
#[macro_use]
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#![feature(test, rustc_macro, rustc_attrs)]
|
||||
#![feature(test, proc_macro)]
|
||||
|
||||
#[macro_use]
|
||||
extern crate serde_derive;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "serde_test"
|
||||
version = "0.8.11"
|
||||
version = "0.8.14"
|
||||
authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>"]
|
||||
license = "MIT/Apache-2.0"
|
||||
description = "Token De/Serializer for testing De/Serialize implementations"
|
||||
@@ -12,4 +12,4 @@ keywords = ["serde", "serialization"]
|
||||
include = ["Cargo.toml", "src/**/*.rs"]
|
||||
|
||||
[dependencies]
|
||||
serde = { version = "0.8.11", path = "../serde" }
|
||||
serde = { version = "0.8.14", path = "../serde" }
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "serde_testing"
|
||||
version = "0.8.11"
|
||||
version = "0.8.14"
|
||||
authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>"]
|
||||
license = "MIT/Apache-2.0"
|
||||
description = "A generic serialization/deserialization framework"
|
||||
|
||||
Reference in New Issue
Block a user