mirror of
https://github.com/pezkuwichain/serde.git
synced 2026-04-28 20:47:56 +00:00
Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| b97a183e82 | |||
| 9433004307 | |||
| 9476838264 | |||
| 172edc4cf4 | |||
| 3c97e1b9a9 | |||
| a81968af3c |
+2
-2
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "serde"
|
name = "serde"
|
||||||
version = "1.0.108" # remember to update html_root_url and serde_derive dependency
|
version = "1.0.109" # remember to update html_root_url and serde_derive dependency
|
||||||
authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>", "David Tolnay <dtolnay@gmail.com>"]
|
authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>", "David Tolnay <dtolnay@gmail.com>"]
|
||||||
license = "MIT OR Apache-2.0"
|
license = "MIT OR Apache-2.0"
|
||||||
description = "A generic serialization/deserialization framework"
|
description = "A generic serialization/deserialization framework"
|
||||||
@@ -14,7 +14,7 @@ include = ["Cargo.toml", "build.rs", "src/**/*.rs", "crates-io.md", "README.md",
|
|||||||
build = "build.rs"
|
build = "build.rs"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
serde_derive = { version = "=1.0.108", optional = true, path = "../serde_derive" }
|
serde_derive = { version = "=1.0.109", optional = true, path = "../serde_derive" }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
serde_derive = { version = "1.0", path = "../serde_derive" }
|
serde_derive = { version = "1.0", path = "../serde_derive" }
|
||||||
|
|||||||
+1
-1
@@ -75,7 +75,7 @@
|
|||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
// Serde types in rustdoc of other crates get linked to here.
|
// Serde types in rustdoc of other crates get linked to here.
|
||||||
#![doc(html_root_url = "https://docs.rs/serde/1.0.108")]
|
#![doc(html_root_url = "https://docs.rs/serde/1.0.109")]
|
||||||
// Support using Serde without the standard library!
|
// Support using Serde without the standard library!
|
||||||
#![cfg_attr(not(feature = "std"), no_std)]
|
#![cfg_attr(not(feature = "std"), no_std)]
|
||||||
// Unstable functionality only if the user asks for it. For tracking and
|
// Unstable functionality only if the user asks for it. For tracking and
|
||||||
|
|||||||
@@ -616,7 +616,7 @@ impl Serialize for SystemTime {
|
|||||||
use super::SerializeStruct;
|
use super::SerializeStruct;
|
||||||
let duration_since_epoch = self
|
let duration_since_epoch = self
|
||||||
.duration_since(UNIX_EPOCH)
|
.duration_since(UNIX_EPOCH)
|
||||||
.expect("SystemTime must be later than UNIX_EPOCH");
|
.map_err(|_| S::Error::custom("SystemTime must be later than UNIX_EPOCH"))?;
|
||||||
let mut state = try!(serializer.serialize_struct("SystemTime", 2));
|
let mut state = try!(serializer.serialize_struct("SystemTime", 2));
|
||||||
try!(state.serialize_field("secs_since_epoch", &duration_since_epoch.as_secs()));
|
try!(state.serialize_field("secs_since_epoch", &duration_since_epoch.as_secs()));
|
||||||
try!(state.serialize_field("nanos_since_epoch", &duration_since_epoch.subsec_nanos()));
|
try!(state.serialize_field("nanos_since_epoch", &duration_since_epoch.subsec_nanos()));
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "serde_derive"
|
name = "serde_derive"
|
||||||
version = "1.0.108" # remember to update html_root_url
|
version = "1.0.109" # remember to update html_root_url
|
||||||
authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>", "David Tolnay <dtolnay@gmail.com>"]
|
authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>", "David Tolnay <dtolnay@gmail.com>"]
|
||||||
license = "MIT OR Apache-2.0"
|
license = "MIT OR Apache-2.0"
|
||||||
description = "Macros 1.1 implementation of #[derive(Serialize, Deserialize)]"
|
description = "Macros 1.1 implementation of #[derive(Serialize, Deserialize)]"
|
||||||
|
|||||||
+32
-27
@@ -1377,39 +1377,44 @@ fn deserialize_adjacently_tagged_enum(
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
fn is_unit(variant: &Variant) -> bool {
|
|
||||||
match variant.style {
|
|
||||||
Style::Unit => true,
|
|
||||||
Style::Struct | Style::Tuple | Style::Newtype => false,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut missing_content = quote! {
|
let mut missing_content = quote! {
|
||||||
_serde::export::Err(<__A::Error as _serde::de::Error>::missing_field(#content))
|
_serde::export::Err(<__A::Error as _serde::de::Error>::missing_field(#content))
|
||||||
};
|
};
|
||||||
if variants.iter().any(is_unit) {
|
let mut missing_content_fallthrough = quote!();
|
||||||
let fallthrough = if variants.iter().all(is_unit) {
|
let mut missing_content_arms = variants
|
||||||
None
|
.iter()
|
||||||
} else {
|
.enumerate()
|
||||||
Some(quote! {
|
.filter(|&(_, variant)| !variant.attrs.skip_deserializing())
|
||||||
_ => #missing_content
|
.filter_map(|(i, variant)| {
|
||||||
})
|
let variant_index = field_i(i);
|
||||||
};
|
let variant_ident = &variant.ident;
|
||||||
let arms = variants
|
|
||||||
.iter()
|
let arm = match variant.style {
|
||||||
.enumerate()
|
Style::Unit => quote! {
|
||||||
.filter(|&(_, variant)| !variant.attrs.skip_deserializing() && is_unit(variant))
|
_serde::export::Ok(#this::#variant_ident)
|
||||||
.map(|(i, variant)| {
|
},
|
||||||
let variant_index = field_i(i);
|
Style::Newtype if variant.attrs.deserialize_with().is_none() => {
|
||||||
let variant_ident = &variant.ident;
|
let span = variant.original.span();
|
||||||
quote! {
|
let func = quote_spanned!(span=> _serde::private::de::missing_field);
|
||||||
__Field::#variant_index => _serde::export::Ok(#this::#variant_ident),
|
quote! {
|
||||||
|
#func(#content).map(#this::#variant_ident)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
_ => {
|
||||||
|
missing_content_fallthrough = quote!(_ => #missing_content);
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
Some(quote! {
|
||||||
|
__Field::#variant_index => #arm,
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.peekable();
|
||||||
|
if missing_content_arms.peek().is_some() {
|
||||||
missing_content = quote! {
|
missing_content = quote! {
|
||||||
match __field {
|
match __field {
|
||||||
#(#arms)*
|
#(#missing_content_arms)*
|
||||||
#fallthrough
|
#missing_content_fallthrough
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,7 +13,7 @@
|
|||||||
//!
|
//!
|
||||||
//! [https://serde.rs/derive.html]: https://serde.rs/derive.html
|
//! [https://serde.rs/derive.html]: https://serde.rs/derive.html
|
||||||
|
|
||||||
#![doc(html_root_url = "https://docs.rs/serde_derive/1.0.108")]
|
#![doc(html_root_url = "https://docs.rs/serde_derive/1.0.109")]
|
||||||
#![allow(unknown_lints, bare_trait_objects)]
|
#![allow(unknown_lints, bare_trait_objects)]
|
||||||
#![deny(clippy::all, clippy::pedantic)]
|
#![deny(clippy::all, clippy::pedantic)]
|
||||||
// Ignored clippy lints
|
// Ignored clippy lints
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "serde_test"
|
name = "serde_test"
|
||||||
version = "1.0.108" # remember to update html_root_url
|
version = "1.0.109" # remember to update html_root_url
|
||||||
authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>", "David Tolnay <dtolnay@gmail.com>"]
|
authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>", "David Tolnay <dtolnay@gmail.com>"]
|
||||||
license = "MIT OR Apache-2.0"
|
license = "MIT OR Apache-2.0"
|
||||||
description = "Token De/Serializer for testing De/Serialize implementations"
|
description = "Token De/Serializer for testing De/Serialize implementations"
|
||||||
|
|||||||
@@ -144,7 +144,7 @@
|
|||||||
//! # }
|
//! # }
|
||||||
//! ```
|
//! ```
|
||||||
|
|
||||||
#![doc(html_root_url = "https://docs.rs/serde_test/1.0.108")]
|
#![doc(html_root_url = "https://docs.rs/serde_test/1.0.109")]
|
||||||
#![cfg_attr(feature = "cargo-clippy", allow(renamed_and_removed_lints))]
|
#![cfg_attr(feature = "cargo-clippy", allow(renamed_and_removed_lints))]
|
||||||
#![cfg_attr(feature = "cargo-clippy", deny(clippy, clippy_pedantic))]
|
#![cfg_attr(feature = "cargo-clippy", deny(clippy, clippy_pedantic))]
|
||||||
// Ignored clippy lints
|
// Ignored clippy lints
|
||||||
|
|||||||
@@ -1145,6 +1145,20 @@ fn test_adjacently_tagged_enum() {
|
|||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// optional newtype with no content field
|
||||||
|
assert_de_tokens(
|
||||||
|
&AdjacentlyTagged::Newtype::<Option<u8>>(None),
|
||||||
|
&[
|
||||||
|
Token::Struct {
|
||||||
|
name: "AdjacentlyTagged",
|
||||||
|
len: 1,
|
||||||
|
},
|
||||||
|
Token::Str("t"),
|
||||||
|
Token::Str("Newtype"),
|
||||||
|
Token::StructEnd,
|
||||||
|
],
|
||||||
|
);
|
||||||
|
|
||||||
// tuple with tag first
|
// tuple with tag first
|
||||||
assert_tokens(
|
assert_tokens(
|
||||||
&AdjacentlyTagged::Tuple::<u8>(1, 1),
|
&AdjacentlyTagged::Tuple::<u8>(1, 1),
|
||||||
|
|||||||
Reference in New Issue
Block a user