mirror of
https://github.com/pezkuwichain/serde.git
synced 2026-05-31 21:31:07 +00:00
Compare commits
12 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 08c59a2e0e | |||
| 4a0bf4de65 | |||
| 95ffca9bbe | |||
| 5e47c87ba0 | |||
| c6d5d9be14 | |||
| d63d09f4db | |||
| de6d00c306 | |||
| 5bda95ba81 | |||
| 36641e7b81 | |||
| 6eca34c45c | |||
| 7efa0153b0 | |||
| 8dba87661b |
+1
-1
@@ -1,8 +1,8 @@
|
|||||||
sudo: false
|
sudo: false
|
||||||
language: rust
|
language: rust
|
||||||
rust:
|
rust:
|
||||||
- 1.10.0
|
|
||||||
- 1.11.0
|
- 1.11.0
|
||||||
|
- 1.12.0
|
||||||
- stable
|
- stable
|
||||||
- beta
|
- beta
|
||||||
- nightly
|
- nightly
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "serde"
|
name = "serde"
|
||||||
version = "0.8.18"
|
version = "0.8.20"
|
||||||
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"
|
||||||
|
|||||||
@@ -283,6 +283,12 @@ impl Visitor for StringVisitor {
|
|||||||
Ok(v)
|
Ok(v)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn visit_unit<E>(&mut self) -> Result<String, E>
|
||||||
|
where E: Error,
|
||||||
|
{
|
||||||
|
Ok(String::new())
|
||||||
|
}
|
||||||
|
|
||||||
fn visit_bytes<E>(&mut self, v: &[u8]) -> Result<String, E>
|
fn visit_bytes<E>(&mut self, v: &[u8]) -> Result<String, E>
|
||||||
where E: Error,
|
where E: Error,
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "serde_codegen"
|
name = "serde_codegen"
|
||||||
version = "0.8.18"
|
version = "0.8.20"
|
||||||
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.3"
|
quote = "0.3.8"
|
||||||
serde_codegen_internals = { version = "=0.11.0", default-features = false, path = "../serde_codegen_internals" }
|
serde_codegen_internals = { version = "=0.11.2", default-features = false, path = "../serde_codegen_internals" }
|
||||||
syn = { version = "0.10", features = ["aster", "visit"] }
|
syn = { version = "0.10", features = ["aster", "visit"] }
|
||||||
syntex = { version = "^0.50.0", optional = true }
|
syntex = { version = "^0.50.0", optional = true }
|
||||||
syntex_syntax = { version = "^0.50.0", optional = true }
|
syntex_syntax = { version = "^0.50.0", optional = true }
|
||||||
|
|||||||
@@ -496,6 +496,7 @@ fn deserialize_item_enum(
|
|||||||
|
|
||||||
let variant_visitor = deserialize_field_visitor(
|
let variant_visitor = deserialize_field_visitor(
|
||||||
variants.iter()
|
variants.iter()
|
||||||
|
.filter(|variant| !variant.attrs.skip_deserializing())
|
||||||
.map(|variant| variant.attrs.name().deserialize_name())
|
.map(|variant| variant.attrs.name().deserialize_name())
|
||||||
.collect(),
|
.collect(),
|
||||||
item_attrs,
|
item_attrs,
|
||||||
@@ -518,7 +519,7 @@ fn deserialize_item_enum(
|
|||||||
|
|
||||||
// Match arms to extract a variant from a string
|
// Match arms to extract a variant from a string
|
||||||
let mut variant_arms = vec![];
|
let mut variant_arms = vec![];
|
||||||
for (i, variant) in variants.iter().enumerate() {
|
for (i, variant) in variants.iter().filter(|variant| !variant.attrs.skip_deserializing()).enumerate() {
|
||||||
let variant_name = aster::id(format!("__field{}", i));
|
let variant_name = aster::id(format!("__field{}", i));
|
||||||
let variant_name = quote!(__Field::#variant_name);
|
let variant_name = quote!(__Field::#variant_name);
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
#![cfg_attr(feature = "clippy", feature(plugin))]
|
#![cfg_attr(feature = "clippy", feature(plugin))]
|
||||||
#![cfg_attr(feature = "clippy", allow(too_many_arguments))]
|
#![cfg_attr(feature = "clippy", allow(too_many_arguments))]
|
||||||
#![cfg_attr(feature = "clippy", allow(used_underscore_binding))]
|
#![cfg_attr(feature = "clippy", allow(used_underscore_binding))]
|
||||||
#![cfg_attr(not(feature = "with-syntex"), feature(rustc_private, plugin))]
|
|
||||||
|
|
||||||
// The `quote!` macro requires deep recursion.
|
// The `quote!` macro requires deep recursion.
|
||||||
#![recursion_limit = "192"]
|
#![recursion_limit = "192"]
|
||||||
@@ -16,13 +15,6 @@ extern crate syntex;
|
|||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate syntex_syntax as syntax;
|
extern crate syntex_syntax as syntax;
|
||||||
|
|
||||||
#[cfg(not(feature = "with-syntex"))]
|
|
||||||
#[macro_use]
|
|
||||||
extern crate syntax;
|
|
||||||
|
|
||||||
#[cfg(not(feature = "with-syntex"))]
|
|
||||||
extern crate rustc_plugin;
|
|
||||||
|
|
||||||
extern crate syn;
|
extern crate syn;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate quote;
|
extern crate quote;
|
||||||
@@ -30,9 +22,6 @@ extern crate quote;
|
|||||||
#[cfg(feature = "with-syntex")]
|
#[cfg(feature = "with-syntex")]
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
#[cfg(not(feature = "with-syntex"))]
|
|
||||||
use syntax::feature_gate::AttributeType;
|
|
||||||
|
|
||||||
mod bound;
|
mod bound;
|
||||||
mod de;
|
mod de;
|
||||||
mod ser;
|
mod ser;
|
||||||
@@ -104,21 +93,6 @@ pub fn expand<S, D>(src: S, dst: D) -> Result<(), syntex::Error>
|
|||||||
syntex::with_extra_stack(expand_thread)
|
syntex::with_extra_stack(expand_thread)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(feature = "with-syntex"))]
|
|
||||||
pub fn register(reg: &mut rustc_plugin::Registry) {
|
|
||||||
reg.register_syntax_extension(
|
|
||||||
syntax::parse::token::intern("derive_Serialize"),
|
|
||||||
syntax::ext::base::MultiDecorator(
|
|
||||||
Box::new(shim::expand_derive_serialize)));
|
|
||||||
|
|
||||||
reg.register_syntax_extension(
|
|
||||||
syntax::parse::token::intern("derive_Deserialize"),
|
|
||||||
syntax::ext::base::MultiDecorator(
|
|
||||||
Box::new(shim::expand_derive_deserialize)));
|
|
||||||
|
|
||||||
reg.register_attribute("serde".to_owned(), AttributeType::Normal);
|
|
||||||
}
|
|
||||||
|
|
||||||
macro_rules! shim {
|
macro_rules! shim {
|
||||||
($name:ident $pkg:ident :: $func:ident) => {
|
($name:ident $pkg:ident :: $func:ident) => {
|
||||||
pub fn $func(
|
pub fn $func(
|
||||||
@@ -176,6 +150,7 @@ macro_rules! shim {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "with-syntex")]
|
||||||
mod shim {
|
mod shim {
|
||||||
shim!(Serialize ser::expand_derive_serialize);
|
shim!(Serialize ser::expand_derive_serialize);
|
||||||
shim!(Deserialize de::expand_derive_deserialize);
|
shim!(Deserialize de::expand_derive_deserialize);
|
||||||
@@ -184,15 +159,15 @@ mod shim {
|
|||||||
#[cfg(feature = "with-syn")]
|
#[cfg(feature = "with-syn")]
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
/// Not public API. Use the serde_derive crate.
|
/// Not public API. Use the serde_derive crate.
|
||||||
pub fn expand_derive_serialize(item: &str) -> Result<String, String> {
|
pub fn expand_derive_serialize(item: &str) -> Result<quote::Tokens, String> {
|
||||||
let syn_item = syn::parse_macro_input(item).unwrap();
|
let syn_item = syn::parse_macro_input(item).unwrap();
|
||||||
ser::expand_derive_serialize(&syn_item).map(|derive| derive.to_string())
|
ser::expand_derive_serialize(&syn_item)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "with-syn")]
|
#[cfg(feature = "with-syn")]
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
/// Not public API. Use the serde_derive crate.
|
/// Not public API. Use the serde_derive crate.
|
||||||
pub fn expand_derive_deserialize(item: &str) -> Result<String, String> {
|
pub fn expand_derive_deserialize(item: &str) -> Result<quote::Tokens, String> {
|
||||||
let syn_item = syn::parse_macro_input(item).unwrap();
|
let syn_item = syn::parse_macro_input(item).unwrap();
|
||||||
de::expand_derive_deserialize(&syn_item).map(|derive| derive.to_string())
|
de::expand_derive_deserialize(&syn_item)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "serde_codegen_internals"
|
name = "serde_codegen_internals"
|
||||||
version = "0.11.0"
|
version = "0.11.2"
|
||||||
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."
|
||||||
|
|||||||
@@ -187,12 +187,14 @@ impl Item {
|
|||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Variant {
|
pub struct Variant {
|
||||||
name: Name,
|
name: Name,
|
||||||
|
skip_deserializing: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Variant {
|
impl Variant {
|
||||||
pub fn from_ast(cx: &Ctxt, variant: &syn::Variant) -> Self {
|
pub fn from_ast(cx: &Ctxt, variant: &syn::Variant) -> Self {
|
||||||
let mut ser_name = Attr::none(cx, "rename");
|
let mut ser_name = Attr::none(cx, "rename");
|
||||||
let mut de_name = Attr::none(cx, "rename");
|
let mut de_name = Attr::none(cx, "rename");
|
||||||
|
let mut skip_deserializing = BoolAttr::none(cx, "skip_deserializing");
|
||||||
|
|
||||||
for meta_items in variant.attrs.iter().filter_map(get_serde_meta_items) {
|
for meta_items in variant.attrs.iter().filter_map(get_serde_meta_items) {
|
||||||
for meta_item in meta_items {
|
for meta_item in meta_items {
|
||||||
@@ -212,6 +214,10 @@ impl Variant {
|
|||||||
de_name.set_opt(de);
|
de_name.set_opt(de);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Parse `#[serde(skip_deserializing)]`
|
||||||
|
MetaItem(Word(ref name)) if name == "skip_deserializing" => {
|
||||||
|
skip_deserializing.set_true();
|
||||||
|
}
|
||||||
|
|
||||||
MetaItem(ref meta_item) => {
|
MetaItem(ref meta_item) => {
|
||||||
cx.error(format!("unknown serde variant attribute `{}`",
|
cx.error(format!("unknown serde variant attribute `{}`",
|
||||||
@@ -230,12 +236,17 @@ impl Variant {
|
|||||||
serialize: ser_name.get().unwrap_or_else(|| variant.ident.to_string()),
|
serialize: ser_name.get().unwrap_or_else(|| variant.ident.to_string()),
|
||||||
deserialize: de_name.get().unwrap_or_else(|| variant.ident.to_string()),
|
deserialize: de_name.get().unwrap_or_else(|| variant.ident.to_string()),
|
||||||
},
|
},
|
||||||
|
skip_deserializing: skip_deserializing.get(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn name(&self) -> &Name {
|
pub fn name(&self) -> &Name {
|
||||||
&self.name
|
&self.name
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn skip_deserializing(&self) -> bool {
|
||||||
|
self.skip_deserializing
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Represents field attribute information
|
/// Represents field attribute information
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "serde_derive"
|
name = "serde_derive"
|
||||||
version = "0.8.18"
|
version = "0.8.20"
|
||||||
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)]"
|
||||||
@@ -15,7 +15,7 @@ name = "serde_derive"
|
|||||||
proc-macro = true
|
proc-macro = true
|
||||||
|
|
||||||
[dependencies.serde_codegen]
|
[dependencies.serde_codegen]
|
||||||
version = "=0.8.18"
|
version = "=0.8.20"
|
||||||
path = "../serde_codegen"
|
path = "../serde_codegen"
|
||||||
default-features = false
|
default-features = false
|
||||||
features = ["with-syn"]
|
features = ["with-syn"]
|
||||||
@@ -23,5 +23,5 @@ features = ["with-syn"]
|
|||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
compiletest_rs = "^0.2.0"
|
compiletest_rs = "^0.2.0"
|
||||||
fnv = "1.0"
|
fnv = "1.0"
|
||||||
serde = { version = "0.8.18", path = "../serde" }
|
serde = { version = "0.8.20", path = "../serde" }
|
||||||
serde_test = { version = "0.8.18", path = "../serde_test" }
|
serde_test = { version = "0.8.20", path = "../serde_test" }
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "serde_test"
|
name = "serde_test"
|
||||||
version = "0.8.18"
|
version = "0.8.20"
|
||||||
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.18", path = "../serde" }
|
serde = { version = "0.8.20", path = "../serde" }
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "serde_testing"
|
name = "serde_testing"
|
||||||
version = "0.8.18"
|
version = "0.8.20"
|
||||||
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"
|
||||||
|
|||||||
@@ -37,7 +37,9 @@ enum Enum {
|
|||||||
Unit,
|
Unit,
|
||||||
Simple(i32),
|
Simple(i32),
|
||||||
Seq(i32, i32, i32),
|
Seq(i32, i32, i32),
|
||||||
Map { a: i32, b: i32, c: i32 }
|
Map { a: i32, b: i32, c: i32 },
|
||||||
|
#[serde(skip_deserializing)]
|
||||||
|
Skipped,
|
||||||
}
|
}
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
@@ -215,6 +217,9 @@ declare_tests! {
|
|||||||
Token::SeqEnd,
|
Token::SeqEnd,
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
|
test_unit_string {
|
||||||
|
String::new() => &[Token::Unit],
|
||||||
|
}
|
||||||
test_tuple_struct {
|
test_tuple_struct {
|
||||||
TupleStruct(1, 2, 3) => &[
|
TupleStruct(1, 2, 3) => &[
|
||||||
Token::SeqStart(Some(3)),
|
Token::SeqStart(Some(3)),
|
||||||
@@ -802,6 +807,12 @@ declare_error_tests! {
|
|||||||
],
|
],
|
||||||
Error::UnknownVariant("Foo".to_owned()),
|
Error::UnknownVariant("Foo".to_owned()),
|
||||||
}
|
}
|
||||||
|
test_enum_skipped_variant<Enum> {
|
||||||
|
&[
|
||||||
|
Token::EnumUnit("Enum", "Skipped"),
|
||||||
|
],
|
||||||
|
Error::UnknownVariant("Skipped".to_owned()),
|
||||||
|
}
|
||||||
test_struct_seq_too_long<Struct> {
|
test_struct_seq_too_long<Struct> {
|
||||||
&[
|
&[
|
||||||
Token::SeqStart(Some(4)),
|
Token::SeqStart(Some(4)),
|
||||||
|
|||||||
Reference in New Issue
Block a user