mirror of
https://github.com/pezkuwichain/serde.git
synced 2026-04-25 13:57:55 +00:00
Compare commits
19 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 9338c4f1b9 | |||
| 28d67f4172 | |||
| 2401ae61a8 | |||
| 57d3fce0c6 | |||
| a020cceed8 | |||
| 49e985eb90 | |||
| 63def96c66 | |||
| 2fea8c9c28 | |||
| 2c984980a0 | |||
| 36f07912b8 | |||
| 7222cf7514 | |||
| 08c59a2e0e | |||
| 4a0bf4de65 | |||
| 95ffca9bbe | |||
| 5e47c87ba0 | |||
| c6d5d9be14 | |||
| d63d09f4db | |||
| de6d00c306 | |||
| 5bda95ba81 |
@@ -11,6 +11,7 @@ You may be looking for:
|
|||||||
- [Setting up `#[derive(Serialize, Deserialize)]`](https://serde.rs/codegen.html)
|
- [Setting up `#[derive(Serialize, Deserialize)]`](https://serde.rs/codegen.html)
|
||||||
- [Examples](https://serde.rs/examples.html)
|
- [Examples](https://serde.rs/examples.html)
|
||||||
- [API documentation](https://docs.serde.rs/serde/)
|
- [API documentation](https://docs.serde.rs/serde/)
|
||||||
|
- [Release notes](https://github.com/serde-rs/serde/releases)
|
||||||
|
|
||||||
## Serde in action
|
## Serde in action
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "serde"
|
name = "serde"
|
||||||
version = "0.8.19"
|
version = "0.8.21"
|
||||||
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.19"
|
version = "0.8.21"
|
||||||
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.1", default-features = false, path = "../serde_codegen_internals" }
|
serde_codegen_internals = { version = "=0.11.3", 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.52.0", optional = true }
|
||||||
syntex_syntax = { version = "^0.50.0", optional = true }
|
syntex_syntax = { version = "^0.52.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);
|
||||||
|
|
||||||
|
|||||||
+10
-11
@@ -38,11 +38,11 @@ fn syntex_registry() -> syntex::Registry {
|
|||||||
|
|
||||||
impl fold::Folder for StripAttributeFolder {
|
impl fold::Folder for StripAttributeFolder {
|
||||||
fn fold_attribute(&mut self, attr: ast::Attribute) -> Option<ast::Attribute> {
|
fn fold_attribute(&mut self, attr: ast::Attribute) -> Option<ast::Attribute> {
|
||||||
match attr.node.value.node {
|
if attr.value.name == "serde" {
|
||||||
ast::MetaItemKind::List(ref n, _) if n == &"serde" => { return None; }
|
if let ast::MetaItemKind::List(..) = attr.value.node {
|
||||||
_ => {}
|
return None;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Some(attr)
|
Some(attr)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -118,11 +118,10 @@ macro_rules! shim {
|
|||||||
struct MarkSerdeAttributesUsed;
|
struct MarkSerdeAttributesUsed;
|
||||||
impl visit::Visitor for MarkSerdeAttributesUsed {
|
impl visit::Visitor for MarkSerdeAttributesUsed {
|
||||||
fn visit_attribute(&mut self, attr: &ast::Attribute) {
|
fn visit_attribute(&mut self, attr: &ast::Attribute) {
|
||||||
match attr.node.value.node {
|
if attr.value.name == "serde" {
|
||||||
ast::MetaItemKind::List(ref name, _) if name == "serde" => {
|
if let ast::MetaItemKind::List(..) = attr.value.node {
|
||||||
attr::mark_used(attr);
|
attr::mark_used(attr);
|
||||||
}
|
}
|
||||||
_ => {}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -159,15 +158,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)
|
||||||
}
|
}
|
||||||
|
|||||||
+71
-67
@@ -256,76 +256,80 @@ fn serialize_variant(
|
|||||||
let variant_ident = variant.ident.clone();
|
let variant_ident = variant.ident.clone();
|
||||||
let variant_name = variant.attrs.name().serialize_name();
|
let variant_name = variant.attrs.name().serialize_name();
|
||||||
|
|
||||||
match variant.style {
|
if variant.attrs.skip_serializing() {
|
||||||
Style::Unit => {
|
let skipped_msg = format!("The enum variant {}::{} cannot be serialized",
|
||||||
quote! {
|
type_ident, variant_ident);
|
||||||
#type_ident::#variant_ident =>
|
let skipped_err = quote! {
|
||||||
_serde::ser::Serializer::serialize_unit_variant(
|
Err(_serde::ser::Error::invalid_value(#skipped_msg))
|
||||||
_serializer,
|
};
|
||||||
#type_name,
|
let fields_pat = match variant.style {
|
||||||
#variant_index,
|
Style::Unit => quote!(),
|
||||||
#variant_name,
|
Style::Newtype | Style::Tuple => quote!( (..) ),
|
||||||
),
|
Style::Struct => quote!( {..} ),
|
||||||
}
|
};
|
||||||
},
|
quote! {
|
||||||
Style::Newtype => {
|
#type_ident::#variant_ident #fields_pat => #skipped_err,
|
||||||
let block = serialize_newtype_variant(
|
|
||||||
type_name,
|
|
||||||
variant_index,
|
|
||||||
variant_name,
|
|
||||||
ty,
|
|
||||||
generics,
|
|
||||||
&variant.fields[0],
|
|
||||||
);
|
|
||||||
|
|
||||||
quote! {
|
|
||||||
#type_ident::#variant_ident(ref __simple_value) => #block,
|
|
||||||
}
|
|
||||||
},
|
|
||||||
Style::Tuple => {
|
|
||||||
let field_names: Vec<Tokens> = (0 .. variant.fields.len())
|
|
||||||
.map(|i| {
|
|
||||||
let id = aster::id(format!("__field{}", i));
|
|
||||||
quote!(ref #id)
|
|
||||||
})
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
let pat = quote!(#type_ident::#variant_ident(#(#field_names),*));
|
|
||||||
|
|
||||||
let block = serialize_tuple_variant(
|
|
||||||
type_name,
|
|
||||||
variant_index,
|
|
||||||
variant_name,
|
|
||||||
generics,
|
|
||||||
ty,
|
|
||||||
&variant.fields,
|
|
||||||
);
|
|
||||||
|
|
||||||
quote! {
|
|
||||||
#pat => { #block }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Style::Struct => {
|
} else { // variant wasn't skipped
|
||||||
let fields = variant.fields.iter().map(|field| {
|
match variant.style {
|
||||||
let id = match field.ident {
|
Style::Unit => {
|
||||||
Some(ref name) => name.clone(),
|
quote! {
|
||||||
None => panic!("struct variant has unnamed fields"),
|
#type_ident::#variant_ident =>
|
||||||
};
|
_serde::ser::Serializer::serialize_unit_variant(
|
||||||
quote!(ref #id)
|
_serializer,
|
||||||
});
|
#type_name,
|
||||||
let pat = quote!(#type_ident::#variant_ident { #(#fields),* });
|
#variant_index,
|
||||||
|
#variant_name,
|
||||||
|
),
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Style::Newtype => {
|
||||||
|
let block = serialize_newtype_variant(
|
||||||
|
type_name,
|
||||||
|
variant_index,
|
||||||
|
variant_name,
|
||||||
|
ty,
|
||||||
|
generics,
|
||||||
|
&variant.fields[0],
|
||||||
|
);
|
||||||
|
|
||||||
let block = serialize_struct_variant(
|
quote! {
|
||||||
variant_index,
|
#type_ident::#variant_ident(ref __simple_value) => #block,
|
||||||
variant_name,
|
}
|
||||||
generics,
|
},
|
||||||
ty,
|
Style::Tuple => {
|
||||||
&variant.fields,
|
let field_names = (0 .. variant.fields.len())
|
||||||
item_attrs,
|
.map(|i| aster::id(format!("__field{}", i)));
|
||||||
);
|
|
||||||
|
|
||||||
quote! {
|
let block = serialize_tuple_variant(
|
||||||
#pat => { #block }
|
type_name,
|
||||||
|
variant_index,
|
||||||
|
variant_name,
|
||||||
|
generics,
|
||||||
|
ty,
|
||||||
|
&variant.fields,
|
||||||
|
);
|
||||||
|
|
||||||
|
quote! {
|
||||||
|
#type_ident::#variant_ident(#(ref #field_names),*) => { #block }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Style::Struct => {
|
||||||
|
let fields = variant.fields.iter()
|
||||||
|
.map(|f| f.ident.clone().expect("struct variant has unnamed fields"));
|
||||||
|
|
||||||
|
let block = serialize_struct_variant(
|
||||||
|
variant_index,
|
||||||
|
variant_name,
|
||||||
|
generics,
|
||||||
|
ty,
|
||||||
|
&variant.fields,
|
||||||
|
item_attrs,
|
||||||
|
);
|
||||||
|
|
||||||
|
quote! {
|
||||||
|
#type_ident::#variant_ident { #(ref #fields),* } => { #block }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "serde_codegen_internals"
|
name = "serde_codegen_internals"
|
||||||
version = "0.11.1"
|
version = "0.11.3"
|
||||||
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,16 @@ impl Item {
|
|||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Variant {
|
pub struct Variant {
|
||||||
name: Name,
|
name: Name,
|
||||||
|
skip_deserializing: bool,
|
||||||
|
skip_serializing: 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");
|
||||||
|
let mut skip_serializing = BoolAttr::none(cx, "skip_serializing");
|
||||||
|
|
||||||
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 +216,14 @@ 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();
|
||||||
|
}
|
||||||
|
// Parse `#[serde(skip_serializing)]`
|
||||||
|
MetaItem(Word(ref name)) if name == "skip_serializing" => {
|
||||||
|
skip_serializing.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 +242,22 @@ 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(),
|
||||||
|
skip_serializing: skip_serializing.get(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn name(&self) -> &Name {
|
pub fn name(&self) -> &Name {
|
||||||
&self.name
|
&self.name
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn skip_deserializing(&self) -> bool {
|
||||||
|
self.skip_deserializing
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn skip_serializing(&self) -> bool {
|
||||||
|
self.skip_serializing
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Represents field attribute information
|
/// Represents field attribute information
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "serde_derive"
|
name = "serde_derive"
|
||||||
version = "0.8.19"
|
version = "0.8.21"
|
||||||
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.19"
|
version = "=0.8.21"
|
||||||
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.19", path = "../serde" }
|
serde = { version = "0.8.21", path = "../serde" }
|
||||||
serde_test = { version = "0.8.19", path = "../serde_test" }
|
serde_test = { version = "0.8.21", path = "../serde_test" }
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
#![feature(proc_macro, proc_macro_lib)]
|
#![feature(proc_macro, proc_macro_lib)]
|
||||||
#![cfg(not(test))]
|
|
||||||
|
|
||||||
extern crate proc_macro;
|
extern crate proc_macro;
|
||||||
extern crate serde_codegen;
|
extern crate serde_codegen;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "serde_test"
|
name = "serde_test"
|
||||||
version = "0.8.19"
|
version = "0.8.21"
|
||||||
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.19", path = "../serde" }
|
serde = { version = "0.8.21", path = "../serde" }
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "serde_testing"
|
name = "serde_testing"
|
||||||
version = "0.8.19"
|
version = "0.8.21"
|
||||||
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,10 @@ 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 },
|
||||||
|
#[allow(dead_code)]
|
||||||
|
#[serde(skip_deserializing)]
|
||||||
|
Skipped,
|
||||||
}
|
}
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
@@ -215,6 +218,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 +808,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)),
|
||||||
|
|||||||
@@ -30,12 +30,20 @@ struct Struct {
|
|||||||
c: i32,
|
c: i32,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize, PartialEq, Debug)]
|
||||||
enum Enum {
|
enum Enum {
|
||||||
Unit,
|
Unit,
|
||||||
One(i32),
|
One(i32),
|
||||||
Seq(i32, i32),
|
Seq(i32, i32),
|
||||||
Map { a: i32, b: i32 },
|
Map { a: i32, b: i32 },
|
||||||
|
#[serde(skip_serializing)]
|
||||||
|
SkippedUnit,
|
||||||
|
#[serde(skip_serializing)]
|
||||||
|
SkippedOne(i32),
|
||||||
|
#[serde(skip_serializing)]
|
||||||
|
SkippedSeq(i32, i32),
|
||||||
|
#[serde(skip_serializing)]
|
||||||
|
SkippedMap { _a: i32, _b: i32 },
|
||||||
}
|
}
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
@@ -388,3 +396,23 @@ fn test_cannot_serialize_paths() {
|
|||||||
&[],
|
&[],
|
||||||
Error::InvalidValue("Path contains invalid UTF-8 characters".to_owned()));
|
Error::InvalidValue("Path contains invalid UTF-8 characters".to_owned()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_enum_skipped() {
|
||||||
|
assert_ser_tokens_error(
|
||||||
|
&Enum::SkippedUnit,
|
||||||
|
&[],
|
||||||
|
Error::InvalidValue("The enum variant Enum::SkippedUnit cannot be serialized".to_owned()));
|
||||||
|
assert_ser_tokens_error(
|
||||||
|
&Enum::SkippedOne(42),
|
||||||
|
&[],
|
||||||
|
Error::InvalidValue("The enum variant Enum::SkippedOne cannot be serialized".to_owned()));
|
||||||
|
assert_ser_tokens_error(
|
||||||
|
&Enum::SkippedSeq(1, 2),
|
||||||
|
&[],
|
||||||
|
Error::InvalidValue("The enum variant Enum::SkippedSeq cannot be serialized".to_owned()));
|
||||||
|
assert_ser_tokens_error(
|
||||||
|
&Enum::SkippedMap { _a: 1, _b: 2 },
|
||||||
|
&[],
|
||||||
|
Error::InvalidValue("The enum variant Enum::SkippedMap cannot be serialized".to_owned()));
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user