mirror of
https://github.com/pezkuwichain/serde.git
synced 2026-04-24 00:38:00 +00:00
Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 05a5b7e3c6 | |||
| 3bff326fb3 | |||
| aaadd93878 | |||
| 9c864f0b02 | |||
| 070cce0d9c | |||
| b58e8bac12 | |||
| ada50b077e | |||
| 5e313a7330 | |||
| 2a36d11238 |
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "serde_derive"
|
||||
version = "1.0.182"
|
||||
version = "1.0.183"
|
||||
authors = ["David Tolnay <dtolnay@gmail.com>"]
|
||||
publish = false
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "serde_derive"
|
||||
version = "1.0.182"
|
||||
version = "1.0.183"
|
||||
authors = ["David Tolnay <dtolnay@gmail.com>"]
|
||||
categories = ["no-std", "no-std::no-alloc"]
|
||||
description = "Implementation of #[derive(Serialize, Deserialize)]"
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
//!
|
||||
//! [https://serde.rs/derive.html]: https://serde.rs/derive.html
|
||||
|
||||
#![doc(html_root_url = "https://docs.rs/serde_derive/1.0.182")]
|
||||
#![doc(html_root_url = "https://docs.rs/serde_derive/1.0.183")]
|
||||
|
||||
#[cfg(not(all(target_arch = "x86_64", target_os = "linux", target_env = "gnu")))]
|
||||
include!("lib_from_source.rs");
|
||||
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "serde"
|
||||
version = "1.0.182" # remember to update html_root_url and serde_derive dependency
|
||||
version = "1.0.183" # remember to update html_root_url and serde_derive dependency
|
||||
authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>", "David Tolnay <dtolnay@gmail.com>"]
|
||||
build = "build.rs"
|
||||
categories = ["encoding", "no-std", "no-std::no-alloc"]
|
||||
@@ -15,7 +15,7 @@ repository = "https://github.com/serde-rs/serde"
|
||||
rust-version = "1.31"
|
||||
|
||||
[dependencies]
|
||||
serde_derive = { version = "=1.0.182", optional = true, path = "../serde_derive" }
|
||||
serde_derive = { version = "=1.0.183", optional = true, path = "../serde_derive" }
|
||||
|
||||
[dev-dependencies]
|
||||
serde_derive = { version = "1", path = "../serde_derive" }
|
||||
|
||||
@@ -1789,6 +1789,9 @@ forwarded_impl!((T), Box<[T]>, Vec::into_boxed_slice);
|
||||
#[cfg(any(feature = "std", feature = "alloc"))]
|
||||
forwarded_impl!((), Box<str>, String::into_boxed_str);
|
||||
|
||||
#[cfg(all(feature = "std", any(unix, windows)))]
|
||||
forwarded_impl!((), Box<OsStr>, OsString::into_boxed_os_str);
|
||||
|
||||
#[cfg(any(feature = "std", feature = "alloc"))]
|
||||
impl<'de, 'a, T: ?Sized> Deserialize<'de> for Cow<'a, T>
|
||||
where
|
||||
|
||||
+1
-1
@@ -93,7 +93,7 @@
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Serde types in rustdoc of other crates get linked to here.
|
||||
#![doc(html_root_url = "https://docs.rs/serde/1.0.182")]
|
||||
#![doc(html_root_url = "https://docs.rs/serde/1.0.183")]
|
||||
// Support using Serde without the standard library!
|
||||
#![cfg_attr(not(feature = "std"), no_std)]
|
||||
// Unstable functionality only if the user asks for it. For tracking and
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "serde_derive"
|
||||
version = "1.0.182" # remember to update html_root_url
|
||||
version = "1.0.183" # remember to update html_root_url
|
||||
authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>", "David Tolnay <dtolnay@gmail.com>"]
|
||||
categories = ["no-std", "no-std::no-alloc"]
|
||||
description = "Macros 1.1 implementation of #[derive(Serialize, Deserialize)]"
|
||||
|
||||
+39
-31
@@ -965,12 +965,7 @@ fn deserialize_struct(
|
||||
)
|
||||
})
|
||||
.collect();
|
||||
let field_visitor = Stmts(deserialize_generated_identifier(
|
||||
&field_names_idents,
|
||||
cattrs,
|
||||
false,
|
||||
None,
|
||||
));
|
||||
let field_visitor = deserialize_field_identifier(&field_names_idents, cattrs);
|
||||
|
||||
// untagged struct variants do not get a visit_seq method. The same applies to
|
||||
// structs that only have a map representation.
|
||||
@@ -1128,12 +1123,7 @@ fn deserialize_struct_in_place(
|
||||
})
|
||||
.collect();
|
||||
|
||||
let field_visitor = Stmts(deserialize_generated_identifier(
|
||||
&field_names_idents,
|
||||
cattrs,
|
||||
false,
|
||||
None,
|
||||
));
|
||||
let field_visitor = deserialize_field_identifier(&field_names_idents, cattrs);
|
||||
|
||||
let mut_seq = if field_names_idents.is_empty() {
|
||||
quote!(_)
|
||||
@@ -1247,7 +1237,12 @@ fn prepare_enum_variant_enum(
|
||||
})
|
||||
.collect();
|
||||
|
||||
let other_idx = deserialized_variants.position(|(_, variant)| variant.attrs.other());
|
||||
let fallthrough = deserialized_variants
|
||||
.position(|(_, variant)| variant.attrs.other())
|
||||
.map(|other_idx| {
|
||||
let ignore_variant = variant_names_idents[other_idx].1.clone();
|
||||
quote!(_serde::__private::Ok(__Field::#ignore_variant))
|
||||
});
|
||||
|
||||
let variants_stmt = {
|
||||
let variant_names = variant_names_idents.iter().map(|(name, _, _)| name);
|
||||
@@ -1261,7 +1256,8 @@ fn prepare_enum_variant_enum(
|
||||
&variant_names_idents,
|
||||
cattrs,
|
||||
true,
|
||||
other_idx,
|
||||
None,
|
||||
fallthrough,
|
||||
));
|
||||
|
||||
(variants_stmt, variant_visitor)
|
||||
@@ -1986,27 +1982,12 @@ fn deserialize_generated_identifier(
|
||||
fields: &[(&str, Ident, &BTreeSet<String>)],
|
||||
cattrs: &attr::Container,
|
||||
is_variant: bool,
|
||||
other_idx: Option<usize>,
|
||||
ignore_variant: Option<TokenStream>,
|
||||
fallthrough: Option<TokenStream>,
|
||||
) -> Fragment {
|
||||
let this_value = quote!(__Field);
|
||||
let field_idents: &Vec<_> = &fields.iter().map(|(_, ident, _)| ident).collect();
|
||||
|
||||
let (ignore_variant, fallthrough) = if !is_variant && cattrs.has_flatten() {
|
||||
let ignore_variant = quote!(__other(_serde::__private::de::Content<'de>),);
|
||||
let fallthrough = quote!(_serde::__private::Ok(__Field::__other(__value)));
|
||||
(Some(ignore_variant), Some(fallthrough))
|
||||
} else if let Some(other_idx) = other_idx {
|
||||
let ignore_variant = fields[other_idx].1.clone();
|
||||
let fallthrough = quote!(_serde::__private::Ok(__Field::#ignore_variant));
|
||||
(None, Some(fallthrough))
|
||||
} else if is_variant || cattrs.deny_unknown_fields() {
|
||||
(None, None)
|
||||
} else {
|
||||
let ignore_variant = quote!(__ignore,);
|
||||
let fallthrough = quote!(_serde::__private::Ok(__Field::__ignore));
|
||||
(Some(ignore_variant), Some(fallthrough))
|
||||
};
|
||||
|
||||
let visitor_impl = Stmts(deserialize_identifier(
|
||||
&this_value,
|
||||
fields,
|
||||
@@ -2052,6 +2033,33 @@ fn deserialize_generated_identifier(
|
||||
}
|
||||
}
|
||||
|
||||
/// Generates enum and its `Deserialize` implementation that represents each
|
||||
/// non-skipped field of the struct
|
||||
fn deserialize_field_identifier(
|
||||
fields: &[(&str, Ident, &BTreeSet<String>)],
|
||||
cattrs: &attr::Container,
|
||||
) -> Stmts {
|
||||
let (ignore_variant, fallthrough) = if cattrs.has_flatten() {
|
||||
let ignore_variant = quote!(__other(_serde::__private::de::Content<'de>),);
|
||||
let fallthrough = quote!(_serde::__private::Ok(__Field::__other(__value)));
|
||||
(Some(ignore_variant), Some(fallthrough))
|
||||
} else if cattrs.deny_unknown_fields() {
|
||||
(None, None)
|
||||
} else {
|
||||
let ignore_variant = quote!(__ignore,);
|
||||
let fallthrough = quote!(_serde::__private::Ok(__Field::__ignore));
|
||||
(Some(ignore_variant), Some(fallthrough))
|
||||
};
|
||||
|
||||
Stmts(deserialize_generated_identifier(
|
||||
fields,
|
||||
cattrs,
|
||||
false,
|
||||
ignore_variant,
|
||||
fallthrough,
|
||||
))
|
||||
}
|
||||
|
||||
// Generates `Deserialize::deserialize` body for an enum with
|
||||
// `serde(field_identifier)` or `serde(variant_identifier)` attribute.
|
||||
fn deserialize_custom_identifier(
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
//!
|
||||
//! [https://serde.rs/derive.html]: https://serde.rs/derive.html
|
||||
|
||||
#![doc(html_root_url = "https://docs.rs/serde_derive/1.0.182")]
|
||||
#![doc(html_root_url = "https://docs.rs/serde_derive/1.0.183")]
|
||||
// Ignored clippy lints
|
||||
#![allow(
|
||||
// clippy false positive: https://github.com/rust-lang/rust-clippy/issues/7054
|
||||
|
||||
Reference in New Issue
Block a user