mirror of
https://github.com/pezkuwichain/serde.git
synced 2026-04-27 14:37:55 +00:00
Compare commits
22 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 24c4df7831 | |||
| a077ae039e | |||
| 20b34d3b43 | |||
| b5451d1905 | |||
| e26960f7f8 | |||
| 228b5a4a63 | |||
| 28db9d4989 | |||
| 5fff0d936d | |||
| 8eb195edf0 | |||
| 8b2e6baf78 | |||
| 4e54aaf796 | |||
| 4cddcbe194 | |||
| 54b6798ef6 | |||
| 229a9d90ba | |||
| 3bcd568c86 | |||
| dc56077aac | |||
| 46bd36e17c | |||
| 5dee9118c7 | |||
| a916aa9420 | |||
| d9c63d0784 | |||
| 41dcb969e8 | |||
| 6dbaea34ba |
@@ -79,12 +79,13 @@ fn main() {
|
|||||||
|
|
||||||
## Getting help
|
## Getting help
|
||||||
|
|
||||||
Serde developers live in the #serde channel on
|
Serde developers live in the #serde channel on [`irc.mozilla.org`][irc]. The
|
||||||
[`irc.mozilla.org`](https://wiki.mozilla.org/IRC). The #rust channel is also a
|
\#rust channel is also a good resource with generally faster response time but
|
||||||
good resource with generally faster response time but less specific knowledge
|
less specific knowledge about Serde. If IRC is not your thing or you don't get a
|
||||||
about Serde. If IRC is not your thing or you don't get a good response, we are
|
good response, we are happy to respond to [GitHub issues][issues] as well.
|
||||||
happy to respond to [GitHub issues](https://github.com/serde-rs/serde/issues/new)
|
|
||||||
as well.
|
[irc]: https://wiki.mozilla.org/IRC
|
||||||
|
[issues]: https://github.com/serde-rs/serde/issues/new/choose
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
|
|||||||
+7
-6
@@ -47,9 +47,10 @@ fn main() {
|
|||||||
|
|
||||||
## Getting help
|
## Getting help
|
||||||
|
|
||||||
Serde developers live in the #serde channel on
|
Serde developers live in the #serde channel on [`irc.mozilla.org`][irc]. The
|
||||||
[`irc.mozilla.org`](https://wiki.mozilla.org/IRC). The #rust channel is also a
|
\#rust channel is also a good resource with generally faster response time but
|
||||||
good resource with generally faster response time but less specific knowledge
|
less specific knowledge about Serde. If IRC is not your thing or you don't get a
|
||||||
about Serde. If IRC is not your thing or you don't get a good response, we are
|
good response, we are happy to respond to [GitHub issues][issues] as well.
|
||||||
happy to respond to [GitHub issues](https://github.com/serde-rs/serde/issues/new)
|
|
||||||
as well.
|
[irc]: https://wiki.mozilla.org/IRC
|
||||||
|
[issues]: https://github.com/serde-rs/serde/issues/new/choose
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "serde"
|
name = "serde"
|
||||||
version = "1.0.67" # remember to update html_root_url
|
version = "1.0.71" # 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/Apache-2.0"
|
license = "MIT/Apache-2.0"
|
||||||
description = "A generic serialization/deserialization framework"
|
description = "A generic serialization/deserialization framework"
|
||||||
|
|||||||
@@ -36,6 +36,12 @@ fn main() {
|
|||||||
println!("cargo:rustc-cfg=integer128");
|
println!("cargo:rustc-cfg=integer128");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Inclusive ranges methods stabilized in Rust 1.27:
|
||||||
|
// https://github.com/rust-lang/rust/pull/50758
|
||||||
|
if minor >= 27 {
|
||||||
|
println!("cargo:rustc-cfg=range_inclusive");
|
||||||
|
}
|
||||||
|
|
||||||
// Non-zero integers stabilized in Rust 1.28:
|
// Non-zero integers stabilized in Rust 1.28:
|
||||||
// https://github.com/rust-lang/rust/pull/50808
|
// https://github.com/rust-lang/rust/pull/50808
|
||||||
if minor >= 28 {
|
if minor >= 28 {
|
||||||
|
|||||||
+192
-132
@@ -1602,7 +1602,13 @@ forwarded_impl!((T), Box<[T]>, Vec::into_boxed_slice);
|
|||||||
#[cfg(any(feature = "std", feature = "alloc"))]
|
#[cfg(any(feature = "std", feature = "alloc"))]
|
||||||
forwarded_impl!((), Box<str>, String::into_boxed_str);
|
forwarded_impl!((), Box<str>, String::into_boxed_str);
|
||||||
|
|
||||||
#[cfg(all(not(de_rc_dst), feature = "rc", any(feature = "std", feature = "alloc")))]
|
#[cfg(
|
||||||
|
all(
|
||||||
|
not(de_rc_dst),
|
||||||
|
feature = "rc",
|
||||||
|
any(feature = "std", feature = "alloc")
|
||||||
|
)
|
||||||
|
)]
|
||||||
forwarded_impl! {
|
forwarded_impl! {
|
||||||
/// This impl requires the [`"rc"`] Cargo feature of Serde.
|
/// This impl requires the [`"rc"`] Cargo feature of Serde.
|
||||||
///
|
///
|
||||||
@@ -1614,7 +1620,13 @@ forwarded_impl! {
|
|||||||
(T), Arc<T>, Arc::new
|
(T), Arc<T>, Arc::new
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(all(not(de_rc_dst), feature = "rc", any(feature = "std", feature = "alloc")))]
|
#[cfg(
|
||||||
|
all(
|
||||||
|
not(de_rc_dst),
|
||||||
|
feature = "rc",
|
||||||
|
any(feature = "std", feature = "alloc")
|
||||||
|
)
|
||||||
|
)]
|
||||||
forwarded_impl! {
|
forwarded_impl! {
|
||||||
/// This impl requires the [`"rc"`] Cargo feature of Serde.
|
/// This impl requires the [`"rc"`] Cargo feature of Serde.
|
||||||
///
|
///
|
||||||
@@ -1681,7 +1693,13 @@ where
|
|||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#[cfg(all(de_rc_dst, feature = "rc", any(feature = "std", feature = "alloc")))]
|
#[cfg(
|
||||||
|
all(
|
||||||
|
de_rc_dst,
|
||||||
|
feature = "rc",
|
||||||
|
any(feature = "std", feature = "alloc")
|
||||||
|
)
|
||||||
|
)]
|
||||||
macro_rules! box_forwarded_impl {
|
macro_rules! box_forwarded_impl {
|
||||||
(
|
(
|
||||||
$(#[doc = $doc:tt])*
|
$(#[doc = $doc:tt])*
|
||||||
@@ -1702,7 +1720,13 @@ macro_rules! box_forwarded_impl {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(all(de_rc_dst, feature = "rc", any(feature = "std", feature = "alloc")))]
|
#[cfg(
|
||||||
|
all(
|
||||||
|
de_rc_dst,
|
||||||
|
feature = "rc",
|
||||||
|
any(feature = "std", feature = "alloc")
|
||||||
|
)
|
||||||
|
)]
|
||||||
box_forwarded_impl! {
|
box_forwarded_impl! {
|
||||||
/// This impl requires the [`"rc"`] Cargo feature of Serde.
|
/// This impl requires the [`"rc"`] Cargo feature of Serde.
|
||||||
///
|
///
|
||||||
@@ -1714,7 +1738,13 @@ box_forwarded_impl! {
|
|||||||
Rc
|
Rc
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(all(de_rc_dst, feature = "rc", any(feature = "std", feature = "alloc")))]
|
#[cfg(
|
||||||
|
all(
|
||||||
|
de_rc_dst,
|
||||||
|
feature = "rc",
|
||||||
|
any(feature = "std", feature = "alloc")
|
||||||
|
)
|
||||||
|
)]
|
||||||
box_forwarded_impl! {
|
box_forwarded_impl! {
|
||||||
/// This impl requires the [`"rc"`] Cargo feature of Serde.
|
/// This impl requires the [`"rc"`] Cargo feature of Serde.
|
||||||
///
|
///
|
||||||
@@ -2024,8 +2054,7 @@ impl<'de> Deserialize<'de> for SystemTime {
|
|||||||
// start: u64,
|
// start: u64,
|
||||||
// end: u32,
|
// end: u32,
|
||||||
// }
|
// }
|
||||||
#[cfg(feature = "std")]
|
impl<'de, Idx> Deserialize<'de> for Range<Idx>
|
||||||
impl<'de, Idx> Deserialize<'de> for ops::Range<Idx>
|
|
||||||
where
|
where
|
||||||
Idx: Deserialize<'de>,
|
Idx: Deserialize<'de>,
|
||||||
{
|
{
|
||||||
@@ -2033,134 +2062,165 @@ where
|
|||||||
where
|
where
|
||||||
D: Deserializer<'de>,
|
D: Deserializer<'de>,
|
||||||
{
|
{
|
||||||
// If this were outside of the serde crate, it would just use:
|
let (start, end) = deserializer.deserialize_struct(
|
||||||
//
|
|
||||||
// #[derive(Deserialize)]
|
|
||||||
// #[serde(field_identifier, rename_all = "lowercase")]
|
|
||||||
enum Field {
|
|
||||||
Start,
|
|
||||||
End,
|
|
||||||
};
|
|
||||||
|
|
||||||
impl<'de> Deserialize<'de> for Field {
|
|
||||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
|
||||||
where
|
|
||||||
D: Deserializer<'de>,
|
|
||||||
{
|
|
||||||
struct FieldVisitor;
|
|
||||||
|
|
||||||
impl<'de> Visitor<'de> for FieldVisitor {
|
|
||||||
type Value = Field;
|
|
||||||
|
|
||||||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
|
||||||
formatter.write_str("`start` or `end`")
|
|
||||||
}
|
|
||||||
|
|
||||||
fn visit_str<E>(self, value: &str) -> Result<Self::Value, E>
|
|
||||||
where
|
|
||||||
E: Error,
|
|
||||||
{
|
|
||||||
match value {
|
|
||||||
"start" => Ok(Field::Start),
|
|
||||||
"end" => Ok(Field::End),
|
|
||||||
_ => Err(Error::unknown_field(value, FIELDS)),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn visit_bytes<E>(self, value: &[u8]) -> Result<Self::Value, E>
|
|
||||||
where
|
|
||||||
E: Error,
|
|
||||||
{
|
|
||||||
match value {
|
|
||||||
b"start" => Ok(Field::Start),
|
|
||||||
b"end" => Ok(Field::End),
|
|
||||||
_ => {
|
|
||||||
let value = String::from_utf8_lossy(value);
|
|
||||||
Err(Error::unknown_field(&value, FIELDS))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
deserializer.deserialize_identifier(FieldVisitor)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
struct RangeVisitor<Idx> {
|
|
||||||
phantom: PhantomData<Idx>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'de, Idx> Visitor<'de> for RangeVisitor<Idx>
|
|
||||||
where
|
|
||||||
Idx: Deserialize<'de>,
|
|
||||||
{
|
|
||||||
type Value = ops::Range<Idx>;
|
|
||||||
|
|
||||||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
|
||||||
formatter.write_str("struct Range")
|
|
||||||
}
|
|
||||||
|
|
||||||
fn visit_seq<A>(self, mut seq: A) -> Result<Self::Value, A::Error>
|
|
||||||
where
|
|
||||||
A: SeqAccess<'de>,
|
|
||||||
{
|
|
||||||
let start: Idx = match try!(seq.next_element()) {
|
|
||||||
Some(value) => value,
|
|
||||||
None => {
|
|
||||||
return Err(Error::invalid_length(0, &self));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
let end: Idx = match try!(seq.next_element()) {
|
|
||||||
Some(value) => value,
|
|
||||||
None => {
|
|
||||||
return Err(Error::invalid_length(1, &self));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
Ok(start..end)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error>
|
|
||||||
where
|
|
||||||
A: MapAccess<'de>,
|
|
||||||
{
|
|
||||||
let mut start: Option<Idx> = None;
|
|
||||||
let mut end: Option<Idx> = None;
|
|
||||||
while let Some(key) = try!(map.next_key()) {
|
|
||||||
match key {
|
|
||||||
Field::Start => {
|
|
||||||
if start.is_some() {
|
|
||||||
return Err(<A::Error as Error>::duplicate_field("start"));
|
|
||||||
}
|
|
||||||
start = Some(try!(map.next_value()));
|
|
||||||
}
|
|
||||||
Field::End => {
|
|
||||||
if end.is_some() {
|
|
||||||
return Err(<A::Error as Error>::duplicate_field("end"));
|
|
||||||
}
|
|
||||||
end = Some(try!(map.next_value()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
let start = match start {
|
|
||||||
Some(start) => start,
|
|
||||||
None => return Err(<A::Error as Error>::missing_field("start")),
|
|
||||||
};
|
|
||||||
let end = match end {
|
|
||||||
Some(end) => end,
|
|
||||||
None => return Err(<A::Error as Error>::missing_field("end")),
|
|
||||||
};
|
|
||||||
Ok(start..end)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const FIELDS: &'static [&'static str] = &["start", "end"];
|
|
||||||
deserializer.deserialize_struct(
|
|
||||||
"Range",
|
"Range",
|
||||||
FIELDS,
|
range::FIELDS,
|
||||||
RangeVisitor {
|
range::RangeVisitor {
|
||||||
|
expecting: "struct Range",
|
||||||
phantom: PhantomData,
|
phantom: PhantomData,
|
||||||
},
|
},
|
||||||
)
|
)?;
|
||||||
|
Ok(start..end)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(range_inclusive)]
|
||||||
|
impl<'de, Idx> Deserialize<'de> for RangeInclusive<Idx>
|
||||||
|
where
|
||||||
|
Idx: Deserialize<'de>,
|
||||||
|
{
|
||||||
|
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||||
|
where
|
||||||
|
D: Deserializer<'de>,
|
||||||
|
{
|
||||||
|
let (start, end) = deserializer.deserialize_struct(
|
||||||
|
"RangeInclusive",
|
||||||
|
range::FIELDS,
|
||||||
|
range::RangeVisitor {
|
||||||
|
expecting: "struct RangeInclusive",
|
||||||
|
phantom: PhantomData,
|
||||||
|
},
|
||||||
|
)?;
|
||||||
|
Ok(RangeInclusive::new(start, end))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mod range {
|
||||||
|
use lib::*;
|
||||||
|
|
||||||
|
use de::{Deserialize, Deserializer, Error, MapAccess, SeqAccess, Visitor};
|
||||||
|
|
||||||
|
pub const FIELDS: &'static [&'static str] = &["start", "end"];
|
||||||
|
|
||||||
|
// If this were outside of the serde crate, it would just use:
|
||||||
|
//
|
||||||
|
// #[derive(Deserialize)]
|
||||||
|
// #[serde(field_identifier, rename_all = "lowercase")]
|
||||||
|
enum Field {
|
||||||
|
Start,
|
||||||
|
End,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'de> Deserialize<'de> for Field {
|
||||||
|
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||||
|
where
|
||||||
|
D: Deserializer<'de>,
|
||||||
|
{
|
||||||
|
struct FieldVisitor;
|
||||||
|
|
||||||
|
impl<'de> Visitor<'de> for FieldVisitor {
|
||||||
|
type Value = Field;
|
||||||
|
|
||||||
|
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||||
|
formatter.write_str("`start` or `end`")
|
||||||
|
}
|
||||||
|
|
||||||
|
fn visit_str<E>(self, value: &str) -> Result<Self::Value, E>
|
||||||
|
where
|
||||||
|
E: Error,
|
||||||
|
{
|
||||||
|
match value {
|
||||||
|
"start" => Ok(Field::Start),
|
||||||
|
"end" => Ok(Field::End),
|
||||||
|
_ => Err(Error::unknown_field(value, FIELDS)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn visit_bytes<E>(self, value: &[u8]) -> Result<Self::Value, E>
|
||||||
|
where
|
||||||
|
E: Error,
|
||||||
|
{
|
||||||
|
match value {
|
||||||
|
b"start" => Ok(Field::Start),
|
||||||
|
b"end" => Ok(Field::End),
|
||||||
|
_ => {
|
||||||
|
let value = ::export::from_utf8_lossy(value);
|
||||||
|
Err(Error::unknown_field(&value, FIELDS))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
deserializer.deserialize_identifier(FieldVisitor)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct RangeVisitor<Idx> {
|
||||||
|
pub expecting: &'static str,
|
||||||
|
pub phantom: PhantomData<Idx>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'de, Idx> Visitor<'de> for RangeVisitor<Idx>
|
||||||
|
where
|
||||||
|
Idx: Deserialize<'de>,
|
||||||
|
{
|
||||||
|
type Value = (Idx, Idx);
|
||||||
|
|
||||||
|
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||||
|
formatter.write_str(self.expecting)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn visit_seq<A>(self, mut seq: A) -> Result<Self::Value, A::Error>
|
||||||
|
where
|
||||||
|
A: SeqAccess<'de>,
|
||||||
|
{
|
||||||
|
let start: Idx = match try!(seq.next_element()) {
|
||||||
|
Some(value) => value,
|
||||||
|
None => {
|
||||||
|
return Err(Error::invalid_length(0, &self));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
let end: Idx = match try!(seq.next_element()) {
|
||||||
|
Some(value) => value,
|
||||||
|
None => {
|
||||||
|
return Err(Error::invalid_length(1, &self));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
Ok((start, end))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error>
|
||||||
|
where
|
||||||
|
A: MapAccess<'de>,
|
||||||
|
{
|
||||||
|
let mut start: Option<Idx> = None;
|
||||||
|
let mut end: Option<Idx> = None;
|
||||||
|
while let Some(key) = try!(map.next_key()) {
|
||||||
|
match key {
|
||||||
|
Field::Start => {
|
||||||
|
if start.is_some() {
|
||||||
|
return Err(<A::Error as Error>::duplicate_field("start"));
|
||||||
|
}
|
||||||
|
start = Some(try!(map.next_value()));
|
||||||
|
}
|
||||||
|
Field::End => {
|
||||||
|
if end.is_some() {
|
||||||
|
return Err(<A::Error as Error>::duplicate_field("end"));
|
||||||
|
}
|
||||||
|
end = Some(try!(map.next_value()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let start = match start {
|
||||||
|
Some(start) => start,
|
||||||
|
None => return Err(<A::Error as Error>::missing_field("start")),
|
||||||
|
};
|
||||||
|
let end = match end {
|
||||||
|
Some(end) => end,
|
||||||
|
None => return Err(<A::Error as Error>::missing_field("end")),
|
||||||
|
};
|
||||||
|
Ok((start, end))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -97,6 +97,7 @@
|
|||||||
//! - Path
|
//! - Path
|
||||||
//! - PathBuf
|
//! - PathBuf
|
||||||
//! - Range\<T\>
|
//! - Range\<T\>
|
||||||
|
//! - RangeInclusive\<T\>
|
||||||
//! - num::NonZero*
|
//! - num::NonZero*
|
||||||
//! - `!` *(unstable)*
|
//! - `!` *(unstable)*
|
||||||
//! - **Net types**:
|
//! - **Net types**:
|
||||||
|
|||||||
+16
-5
@@ -82,7 +82,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.67")]
|
#![doc(html_root_url = "https://docs.rs/serde/1.0.71")]
|
||||||
// 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
|
||||||
@@ -96,8 +96,15 @@
|
|||||||
#![cfg_attr(
|
#![cfg_attr(
|
||||||
feature = "cargo-clippy",
|
feature = "cargo-clippy",
|
||||||
allow(
|
allow(
|
||||||
cast_lossless, const_static_lifetime, doc_markdown, linkedlist, needless_pass_by_value,
|
cast_lossless,
|
||||||
redundant_field_names, type_complexity, unreadable_literal, zero_prefixed_literal
|
const_static_lifetime,
|
||||||
|
doc_markdown,
|
||||||
|
linkedlist,
|
||||||
|
needless_pass_by_value,
|
||||||
|
redundant_field_names,
|
||||||
|
type_complexity,
|
||||||
|
unreadable_literal,
|
||||||
|
zero_prefixed_literal
|
||||||
)
|
)
|
||||||
)]
|
)]
|
||||||
// Whitelisted clippy_pedantic lints
|
// Whitelisted clippy_pedantic lints
|
||||||
@@ -148,7 +155,7 @@ mod lib {
|
|||||||
pub use std::*;
|
pub use std::*;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub use self::core::{cmp, iter, mem, num, ops, slice, str};
|
pub use self::core::{cmp, iter, mem, num, slice, str};
|
||||||
pub use self::core::{f32, f64};
|
pub use self::core::{f32, f64};
|
||||||
pub use self::core::{i16, i32, i64, i8, isize};
|
pub use self::core::{i16, i32, i64, i8, isize};
|
||||||
pub use self::core::{u16, u32, u64, u8, usize};
|
pub use self::core::{u16, u32, u64, u8, usize};
|
||||||
@@ -159,6 +166,7 @@ mod lib {
|
|||||||
pub use self::core::default::{self, Default};
|
pub use self::core::default::{self, Default};
|
||||||
pub use self::core::fmt::{self, Debug, Display};
|
pub use self::core::fmt::{self, Debug, Display};
|
||||||
pub use self::core::marker::{self, PhantomData};
|
pub use self::core::marker::{self, PhantomData};
|
||||||
|
pub use self::core::ops::Range;
|
||||||
pub use self::core::option::{self, Option};
|
pub use self::core::option::{self, Option};
|
||||||
pub use self::core::result::{self, Result};
|
pub use self::core::result::{self, Result};
|
||||||
|
|
||||||
@@ -193,7 +201,7 @@ mod lib {
|
|||||||
pub use std::sync::{Arc, Weak as ArcWeak};
|
pub use std::sync::{Arc, Weak as ArcWeak};
|
||||||
|
|
||||||
#[cfg(all(feature = "alloc", not(feature = "std")))]
|
#[cfg(all(feature = "alloc", not(feature = "std")))]
|
||||||
pub use alloc::{BTreeMap, BTreeSet, BinaryHeap, LinkedList, VecDeque};
|
pub use alloc::collections::{BTreeMap, BTreeSet, BinaryHeap, LinkedList, VecDeque};
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
pub use std::collections::{BTreeMap, BTreeSet, BinaryHeap, LinkedList, VecDeque};
|
pub use std::collections::{BTreeMap, BTreeSet, BinaryHeap, LinkedList, VecDeque};
|
||||||
|
|
||||||
@@ -219,6 +227,9 @@ mod lib {
|
|||||||
|
|
||||||
#[cfg(any(core_duration, feature = "std"))]
|
#[cfg(any(core_duration, feature = "std"))]
|
||||||
pub use self::core::time::Duration;
|
pub use self::core::time::Duration;
|
||||||
|
|
||||||
|
#[cfg(range_inclusive)]
|
||||||
|
pub use self::core::ops::RangeInclusive;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|||||||
+2
-2
@@ -128,7 +128,7 @@
|
|||||||
/// [`Deserializer`]: trait.Deserializer.html
|
/// [`Deserializer`]: trait.Deserializer.html
|
||||||
/// [`Visitor`]: de/trait.Visitor.html
|
/// [`Visitor`]: de/trait.Visitor.html
|
||||||
/// [`Deserializer::deserialize_any`]: trait.Deserializer.html#tymethod.deserialize_any
|
/// [`Deserializer::deserialize_any`]: trait.Deserializer.html#tymethod.deserialize_any
|
||||||
#[macro_export]
|
#[macro_export(local_inner_macros)]
|
||||||
macro_rules! forward_to_deserialize_any {
|
macro_rules! forward_to_deserialize_any {
|
||||||
(<$visitor:ident: Visitor<$lifetime:tt>> $($func:ident)*) => {
|
(<$visitor:ident: Visitor<$lifetime:tt>> $($func:ident)*) => {
|
||||||
$(forward_to_deserialize_any_helper!{$func<$lifetime, $visitor>})*
|
$(forward_to_deserialize_any_helper!{$func<$lifetime, $visitor>})*
|
||||||
@@ -157,7 +157,7 @@ macro_rules! forward_to_deserialize_any_method {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
#[macro_export]
|
#[macro_export(local_inner_macros)]
|
||||||
macro_rules! forward_to_deserialize_any_helper {
|
macro_rules! forward_to_deserialize_any_helper {
|
||||||
(bool<$l:tt, $v:ident>) => {
|
(bool<$l:tt, $v:ident>) => {
|
||||||
forward_to_deserialize_any_method!{deserialize_bool<$l, $v>()}
|
forward_to_deserialize_any_method!{deserialize_bool<$l, $v>()}
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ macro_rules! __private_deserialize {
|
|||||||
|
|
||||||
/// Used only by Serde doc tests. Not public API.
|
/// Used only by Serde doc tests. Not public API.
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
#[macro_export]
|
#[macro_export(local_inner_macros)]
|
||||||
macro_rules! __serialize_unimplemented {
|
macro_rules! __serialize_unimplemented {
|
||||||
($($func:ident)*) => {
|
($($func:ident)*) => {
|
||||||
$(
|
$(
|
||||||
@@ -52,7 +52,7 @@ macro_rules! __serialize_unimplemented_method {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
#[macro_export]
|
#[macro_export(local_inner_macros)]
|
||||||
macro_rules! __serialize_unimplemented_helper {
|
macro_rules! __serialize_unimplemented_helper {
|
||||||
(bool) => {
|
(bool) => {
|
||||||
__serialize_unimplemented_method!(serialize_bool(bool) -> Ok);
|
__serialize_unimplemented_method!(serialize_bool(bool) -> Ok);
|
||||||
|
|||||||
+20
-2
@@ -227,8 +227,7 @@ seq_impl!(VecDeque<T>);
|
|||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#[cfg(feature = "std")]
|
impl<Idx> Serialize for Range<Idx>
|
||||||
impl<Idx> Serialize for ops::Range<Idx>
|
|
||||||
where
|
where
|
||||||
Idx: Serialize,
|
Idx: Serialize,
|
||||||
{
|
{
|
||||||
@@ -246,6 +245,25 @@ where
|
|||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#[cfg(range_inclusive)]
|
||||||
|
impl<Idx> Serialize for RangeInclusive<Idx>
|
||||||
|
where
|
||||||
|
Idx: Serialize,
|
||||||
|
{
|
||||||
|
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||||
|
where
|
||||||
|
S: Serializer,
|
||||||
|
{
|
||||||
|
use super::SerializeStruct;
|
||||||
|
let mut state = try!(serializer.serialize_struct("RangeInclusive", 2));
|
||||||
|
try!(state.serialize_field("start", &self.start()));
|
||||||
|
try!(state.serialize_field("end", &self.end()));
|
||||||
|
state.end()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
impl Serialize for () {
|
impl Serialize for () {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||||
|
|||||||
@@ -92,6 +92,7 @@
|
|||||||
//! - Path
|
//! - Path
|
||||||
//! - PathBuf
|
//! - PathBuf
|
||||||
//! - Range\<T\>
|
//! - Range\<T\>
|
||||||
|
//! - RangeInclusive\<T\>
|
||||||
//! - num::NonZero*
|
//! - num::NonZero*
|
||||||
//! - `!` *(unstable)*
|
//! - `!` *(unstable)*
|
||||||
//! - **Net types**:
|
//! - **Net types**:
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "serde_derive"
|
name = "serde_derive"
|
||||||
version = "1.0.67" # remember to update html_root_url
|
version = "1.0.71" # 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/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)]"
|
||||||
|
|||||||
@@ -32,8 +32,7 @@ pub fn without_defaults(generics: &syn::Generics) -> syn::Generics {
|
|||||||
..param.clone()
|
..param.clone()
|
||||||
}),
|
}),
|
||||||
_ => param.clone(),
|
_ => param.clone(),
|
||||||
})
|
}).collect(),
|
||||||
.collect(),
|
|
||||||
..generics.clone()
|
..generics.clone()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -193,8 +192,7 @@ pub fn with_bound(
|
|||||||
.map(|id| syn::TypePath {
|
.map(|id| syn::TypePath {
|
||||||
qself: None,
|
qself: None,
|
||||||
path: id.into(),
|
path: id.into(),
|
||||||
})
|
}).chain(associated_type_usage.into_iter().cloned())
|
||||||
.chain(associated_type_usage.into_iter().cloned())
|
|
||||||
.map(|bounded_ty| {
|
.map(|bounded_ty| {
|
||||||
syn::WherePredicate::Type(syn::PredicateType {
|
syn::WherePredicate::Type(syn::PredicateType {
|
||||||
lifetimes: None,
|
lifetimes: None,
|
||||||
@@ -208,7 +206,7 @@ pub fn with_bound(
|
|||||||
lifetimes: None,
|
lifetimes: None,
|
||||||
path: bound.clone(),
|
path: bound.clone(),
|
||||||
})].into_iter()
|
})].into_iter()
|
||||||
.collect(),
|
.collect(),
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -241,7 +239,7 @@ pub fn with_self_bound(
|
|||||||
lifetimes: None,
|
lifetimes: None,
|
||||||
path: bound.clone(),
|
path: bound.clone(),
|
||||||
})].into_iter()
|
})].into_iter()
|
||||||
.collect(),
|
.collect(),
|
||||||
}));
|
}));
|
||||||
generics
|
generics
|
||||||
}
|
}
|
||||||
@@ -270,8 +268,7 @@ pub fn with_lifetime_bound(generics: &syn::Generics, lifetime: &str) -> syn::Gen
|
|||||||
syn::GenericParam::Const(_) => {}
|
syn::GenericParam::Const(_) => {}
|
||||||
}
|
}
|
||||||
param
|
param
|
||||||
}))
|
})).collect();
|
||||||
.collect();
|
|
||||||
|
|
||||||
syn::Generics {
|
syn::Generics {
|
||||||
params: params,
|
params: params,
|
||||||
@@ -307,13 +304,12 @@ fn type_of_item(cont: &Container) -> syn::Type {
|
|||||||
syn::GenericParam::Const(_) => {
|
syn::GenericParam::Const(_) => {
|
||||||
panic!("Serde does not support const generics yet");
|
panic!("Serde does not support const generics yet");
|
||||||
}
|
}
|
||||||
})
|
}).collect(),
|
||||||
.collect(),
|
|
||||||
gt_token: <Token![>]>::default(),
|
gt_token: <Token![>]>::default(),
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
}].into_iter()
|
}].into_iter()
|
||||||
.collect(),
|
.collect(),
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -73,6 +73,9 @@ pub fn expand_derive_deserialize(input: &syn::DeriveInput) -> Result<TokenStream
|
|||||||
let generated = quote! {
|
let generated = quote! {
|
||||||
#[allow(non_upper_case_globals, unused_attributes, unused_qualifications)]
|
#[allow(non_upper_case_globals, unused_attributes, unused_qualifications)]
|
||||||
const #dummy_const: () = {
|
const #dummy_const: () = {
|
||||||
|
#[allow(unknown_lints)]
|
||||||
|
#[cfg_attr(feature = "cargo-clippy", allow(useless_attribute))]
|
||||||
|
#[allow(rust_2018_idioms)]
|
||||||
extern crate serde as _serde;
|
extern crate serde as _serde;
|
||||||
#try_replacement
|
#try_replacement
|
||||||
#impl_block
|
#impl_block
|
||||||
@@ -201,7 +204,9 @@ fn build_generics(cont: &Container, borrowed: &BorrowedLifetimes) -> syn::Generi
|
|||||||
// All other fields may need a `T: Deserialize` bound where T is the type of the
|
// All other fields may need a `T: Deserialize` bound where T is the type of the
|
||||||
// field.
|
// field.
|
||||||
fn needs_deserialize_bound(field: &attr::Field, variant: Option<&attr::Variant>) -> bool {
|
fn needs_deserialize_bound(field: &attr::Field, variant: Option<&attr::Variant>) -> bool {
|
||||||
!field.skip_deserializing() && field.deserialize_with().is_none() && field.de_bound().is_none()
|
!field.skip_deserializing()
|
||||||
|
&& field.deserialize_with().is_none()
|
||||||
|
&& field.de_bound().is_none()
|
||||||
&& variant.map_or(true, |variant| {
|
&& variant.map_or(true, |variant| {
|
||||||
!variant.skip_deserializing()
|
!variant.skip_deserializing()
|
||||||
&& variant.deserialize_with().is_none()
|
&& variant.deserialize_with().is_none()
|
||||||
@@ -1347,8 +1352,7 @@ fn deserialize_adjacently_tagged_enum(
|
|||||||
quote! {
|
quote! {
|
||||||
__Field::#variant_index => #block
|
__Field::#variant_index => #block
|
||||||
}
|
}
|
||||||
})
|
}).collect();
|
||||||
.collect();
|
|
||||||
|
|
||||||
let expecting = format!("adjacently tagged enum {}", params.type_name());
|
let expecting = format!("adjacently tagged enum {}", params.type_name());
|
||||||
let type_name = cattrs.name().deserialize_name();
|
let type_name = cattrs.name().deserialize_name();
|
||||||
@@ -1936,8 +1940,7 @@ fn deserialize_custom_identifier(
|
|||||||
variant.attrs.name().deserialize_name(),
|
variant.attrs.name().deserialize_name(),
|
||||||
variant.ident.clone(),
|
variant.ident.clone(),
|
||||||
)
|
)
|
||||||
})
|
}).collect();
|
||||||
.collect();
|
|
||||||
|
|
||||||
let names = names_idents.iter().map(|&(ref name, _)| name);
|
let names = names_idents.iter().map(|&(ref name, _)| name);
|
||||||
|
|
||||||
|
|||||||
@@ -129,8 +129,7 @@ fn enum_from_ast<'a>(
|
|||||||
style: style,
|
style: style,
|
||||||
fields: fields,
|
fields: fields,
|
||||||
}
|
}
|
||||||
})
|
}).collect()
|
||||||
.collect()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn struct_from_ast<'a>(
|
fn struct_from_ast<'a>(
|
||||||
@@ -173,6 +172,5 @@ fn fields_from_ast<'a>(
|
|||||||
attrs: attr::Field::from_ast(cx, i, field, attrs, container_default),
|
attrs: attr::Field::from_ast(cx, i, field, attrs, container_default),
|
||||||
ty: &field.ty,
|
ty: &field.ty,
|
||||||
original: field,
|
original: field,
|
||||||
})
|
}).collect()
|
||||||
.collect()
|
|
||||||
}
|
}
|
||||||
|
|||||||
+18
-5
@@ -22,22 +22,35 @@
|
|||||||
//!
|
//!
|
||||||
//! [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.67")]
|
#![doc(html_root_url = "https://docs.rs/serde_derive/1.0.71")]
|
||||||
#![cfg_attr(feature = "cargo-clippy", deny(clippy, clippy_pedantic))]
|
#![cfg_attr(feature = "cargo-clippy", deny(clippy, clippy_pedantic))]
|
||||||
// Whitelisted clippy lints
|
// Whitelisted clippy lints
|
||||||
#![cfg_attr(
|
#![cfg_attr(
|
||||||
feature = "cargo-clippy",
|
feature = "cargo-clippy",
|
||||||
allow(
|
allow(
|
||||||
enum_variant_names, redundant_field_names, too_many_arguments, used_underscore_binding,
|
enum_variant_names,
|
||||||
cyclomatic_complexity, needless_pass_by_value
|
redundant_field_names,
|
||||||
|
too_many_arguments,
|
||||||
|
used_underscore_binding,
|
||||||
|
cyclomatic_complexity,
|
||||||
|
needless_pass_by_value
|
||||||
)
|
)
|
||||||
)]
|
)]
|
||||||
// Whitelisted clippy_pedantic lints
|
// Whitelisted clippy_pedantic lints
|
||||||
#![cfg_attr(
|
#![cfg_attr(
|
||||||
feature = "cargo-clippy",
|
feature = "cargo-clippy",
|
||||||
allow(
|
allow(
|
||||||
items_after_statements, doc_markdown, stutter, similar_names, use_self, single_match_else,
|
items_after_statements,
|
||||||
enum_glob_use, match_same_arms, filter_map, cast_possible_truncation, indexing_slicing,
|
doc_markdown,
|
||||||
|
stutter,
|
||||||
|
similar_names,
|
||||||
|
use_self,
|
||||||
|
single_match_else,
|
||||||
|
enum_glob_use,
|
||||||
|
match_same_arms,
|
||||||
|
filter_map,
|
||||||
|
cast_possible_truncation,
|
||||||
|
indexing_slicing,
|
||||||
)
|
)
|
||||||
)]
|
)]
|
||||||
// The `quote!` macro requires deep recursion.
|
// The `quote!` macro requires deep recursion.
|
||||||
|
|||||||
@@ -62,8 +62,7 @@ fn pretend_fields_used(cont: &Container) -> TokenStream {
|
|||||||
Some(quote!(#type_ident::#variant_ident #pat))
|
Some(quote!(#type_ident::#variant_ident #pat))
|
||||||
}
|
}
|
||||||
_ => None,
|
_ => None,
|
||||||
})
|
}).collect::<Vec<_>>(),
|
||||||
.collect::<Vec<_>>(),
|
|
||||||
Data::Struct(Style::Struct, ref fields) => {
|
Data::Struct(Style::Struct, ref fields) => {
|
||||||
let pat = struct_pattern(fields);
|
let pat = struct_pattern(fields);
|
||||||
vec![quote!(#type_ident #pat)]
|
vec![quote!(#type_ident #pat)]
|
||||||
|
|||||||
+14
-17
@@ -61,6 +61,9 @@ pub fn expand_derive_serialize(input: &syn::DeriveInput) -> Result<TokenStream,
|
|||||||
let generated = quote! {
|
let generated = quote! {
|
||||||
#[allow(non_upper_case_globals, unused_attributes, unused_qualifications)]
|
#[allow(non_upper_case_globals, unused_attributes, unused_qualifications)]
|
||||||
const #dummy_const: () = {
|
const #dummy_const: () = {
|
||||||
|
#[allow(unknown_lints)]
|
||||||
|
#[cfg_attr(feature = "cargo-clippy", allow(useless_attribute))]
|
||||||
|
#[allow(rust_2018_idioms)]
|
||||||
extern crate serde as _serde;
|
extern crate serde as _serde;
|
||||||
#try_replacement
|
#try_replacement
|
||||||
#impl_block
|
#impl_block
|
||||||
@@ -157,7 +160,9 @@ fn build_generics(cont: &Container) -> syn::Generics {
|
|||||||
// attribute specify their own bound so we do not generate one. All other fields
|
// attribute specify their own bound so we do not generate one. All other fields
|
||||||
// may need a `T: Serialize` bound where T is the type of the field.
|
// may need a `T: Serialize` bound where T is the type of the field.
|
||||||
fn needs_serialize_bound(field: &attr::Field, variant: Option<&attr::Variant>) -> bool {
|
fn needs_serialize_bound(field: &attr::Field, variant: Option<&attr::Variant>) -> bool {
|
||||||
!field.skip_serializing() && field.serialize_with().is_none() && field.ser_bound().is_none()
|
!field.skip_serializing()
|
||||||
|
&& field.serialize_with().is_none()
|
||||||
|
&& field.ser_bound().is_none()
|
||||||
&& variant.map_or(true, |variant| {
|
&& variant.map_or(true, |variant| {
|
||||||
!variant.skip_serializing()
|
!variant.skip_serializing()
|
||||||
&& variant.serialize_with().is_none()
|
&& variant.serialize_with().is_none()
|
||||||
@@ -279,8 +284,7 @@ fn serialize_tuple_struct(
|
|||||||
let field_expr = get_member(params, field, &Member::Unnamed(index));
|
let field_expr = get_member(params, field, &Member::Unnamed(index));
|
||||||
quote!(if #path(#field_expr) { 0 } else { 1 })
|
quote!(if #path(#field_expr) { 0 } else { 1 })
|
||||||
}
|
}
|
||||||
})
|
}).fold(quote!(0), |sum, expr| quote!(#sum + #expr));
|
||||||
.fold(quote!(0), |sum, expr| quote!(#sum + #expr));
|
|
||||||
|
|
||||||
quote_block! {
|
quote_block! {
|
||||||
let #let_mut __serde_state = try!(_serde::Serializer::serialize_tuple_struct(__serializer, #type_name, #len));
|
let #let_mut __serde_state = try!(_serde::Serializer::serialize_tuple_struct(__serializer, #type_name, #len));
|
||||||
@@ -323,8 +327,7 @@ fn serialize_struct_as_struct(
|
|||||||
let field_expr = get_member(params, field, &field.member);
|
let field_expr = get_member(params, field, &field.member);
|
||||||
quote!(if #path(#field_expr) { 0 } else { 1 })
|
quote!(if #path(#field_expr) { 0 } else { 1 })
|
||||||
}
|
}
|
||||||
})
|
}).fold(quote!(0), |sum, expr| quote!(#sum + #expr));
|
||||||
.fold(quote!(0), |sum, expr| quote!(#sum + #expr));
|
|
||||||
|
|
||||||
quote_block! {
|
quote_block! {
|
||||||
let #let_mut __serde_state = try!(_serde::Serializer::serialize_struct(__serializer, #type_name, #len));
|
let #let_mut __serde_state = try!(_serde::Serializer::serialize_struct(__serializer, #type_name, #len));
|
||||||
@@ -358,8 +361,7 @@ fn serialize_struct_as_map(
|
|||||||
let field_expr = get_member(params, field, &field.member);
|
let field_expr = get_member(params, field, &field.member);
|
||||||
quote!(if #path(#field_expr) { 0 } else { 1 })
|
quote!(if #path(#field_expr) { 0 } else { 1 })
|
||||||
}
|
}
|
||||||
})
|
}).fold(quote!(0), |sum, expr| quote!(#sum + #expr));
|
||||||
.fold(quote!(0), |sum, expr| quote!(#sum + #expr));
|
|
||||||
quote!(_serde::export::Some(#len))
|
quote!(_serde::export::Some(#len))
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -380,8 +382,7 @@ fn serialize_enum(params: &Parameters, variants: &[Variant], cattrs: &attr::Cont
|
|||||||
.enumerate()
|
.enumerate()
|
||||||
.map(|(variant_index, variant)| {
|
.map(|(variant_index, variant)| {
|
||||||
serialize_variant(params, variant, variant_index as u32, cattrs)
|
serialize_variant(params, variant, variant_index as u32, cattrs)
|
||||||
})
|
}).collect();
|
||||||
.collect();
|
|
||||||
|
|
||||||
quote_expr! {
|
quote_expr! {
|
||||||
match *#self_var {
|
match *#self_var {
|
||||||
@@ -785,8 +786,7 @@ fn serialize_tuple_variant(
|
|||||||
let field_expr = Ident::new(&format!("__field{}", i), Span::call_site());
|
let field_expr = Ident::new(&format!("__field{}", i), Span::call_site());
|
||||||
quote!(if #path(#field_expr) { 0 } else { 1 })
|
quote!(if #path(#field_expr) { 0 } else { 1 })
|
||||||
}
|
}
|
||||||
})
|
}).fold(quote!(0), |sum, expr| quote!(#sum + #expr));
|
||||||
.fold(quote!(0), |sum, expr| quote!(#sum + #expr));
|
|
||||||
|
|
||||||
match context {
|
match context {
|
||||||
TupleVariant::ExternallyTagged {
|
TupleVariant::ExternallyTagged {
|
||||||
@@ -863,8 +863,7 @@ fn serialize_struct_variant<'a>(
|
|||||||
Some(path) => quote!(if #path(#member) { 0 } else { 1 }),
|
Some(path) => quote!(if #path(#member) { 0 } else { 1 }),
|
||||||
None => quote!(1),
|
None => quote!(1),
|
||||||
}
|
}
|
||||||
})
|
}).fold(quote!(0), |sum, expr| quote!(#sum + #expr));
|
||||||
.fold(quote!(0), |sum, expr| quote!(#sum + #expr));
|
|
||||||
|
|
||||||
match context {
|
match context {
|
||||||
StructVariant::ExternallyTagged {
|
StructVariant::ExternallyTagged {
|
||||||
@@ -1043,8 +1042,7 @@ fn serialize_tuple_struct_visitor(
|
|||||||
None => ser,
|
None => ser,
|
||||||
Some(skip) => quote!(if !#skip { #ser }),
|
Some(skip) => quote!(if !#skip { #ser }),
|
||||||
}
|
}
|
||||||
})
|
}).collect()
|
||||||
.collect()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn serialize_struct_visitor(
|
fn serialize_struct_visitor(
|
||||||
@@ -1138,8 +1136,7 @@ fn wrap_serialize_variant_with(
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
quote!(#id)
|
quote!(#id)
|
||||||
})
|
}).collect();
|
||||||
.collect();
|
|
||||||
wrap_serialize_with(
|
wrap_serialize_with(
|
||||||
params,
|
params,
|
||||||
serialize_with,
|
serialize_with,
|
||||||
|
|||||||
@@ -9,7 +9,12 @@
|
|||||||
#![doc(html_root_url = "https://docs.rs/serde_derive_internals/0.23.1")]
|
#![doc(html_root_url = "https://docs.rs/serde_derive_internals/0.23.1")]
|
||||||
#![cfg_attr(
|
#![cfg_attr(
|
||||||
feature = "cargo-clippy",
|
feature = "cargo-clippy",
|
||||||
allow(cyclomatic_complexity, doc_markdown, match_same_arms, redundant_field_names)
|
allow(
|
||||||
|
cyclomatic_complexity,
|
||||||
|
doc_markdown,
|
||||||
|
match_same_arms,
|
||||||
|
redundant_field_names
|
||||||
|
)
|
||||||
)]
|
)]
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "serde_test"
|
name = "serde_test"
|
||||||
version = "1.0.67" # remember to update html_root_url
|
version = "1.0.71" # 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/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"
|
||||||
|
|||||||
@@ -253,7 +253,8 @@ impl<'de, 'a> de::Deserializer<'de> for &'a mut Deserializer<'de> {
|
|||||||
Token::UnitVariant { name: n, .. }
|
Token::UnitVariant { name: n, .. }
|
||||||
| Token::NewtypeVariant { name: n, .. }
|
| Token::NewtypeVariant { name: n, .. }
|
||||||
| Token::TupleVariant { name: n, .. }
|
| Token::TupleVariant { name: n, .. }
|
||||||
| Token::StructVariant { name: n, .. } if name == n =>
|
| Token::StructVariant { name: n, .. }
|
||||||
|
if name == n =>
|
||||||
{
|
{
|
||||||
visitor.visit_enum(DeserializerEnumVisitor { de: self })
|
visitor.visit_enum(DeserializerEnumVisitor { de: self })
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -161,7 +161,7 @@
|
|||||||
//! # }
|
//! # }
|
||||||
//! ```
|
//! ```
|
||||||
|
|
||||||
#![doc(html_root_url = "https://docs.rs/serde_test/1.0.67")]
|
#![doc(html_root_url = "https://docs.rs/serde_test/1.0.71")]
|
||||||
#![cfg_attr(feature = "cargo-clippy", deny(clippy, clippy_pedantic))]
|
#![cfg_attr(feature = "cargo-clippy", deny(clippy, clippy_pedantic))]
|
||||||
// Whitelisted clippy lints
|
// Whitelisted clippy lints
|
||||||
#![cfg_attr(feature = "cargo-clippy", allow(float_cmp))]
|
#![cfg_attr(feature = "cargo-clippy", allow(float_cmp))]
|
||||||
@@ -169,8 +169,12 @@
|
|||||||
#![cfg_attr(
|
#![cfg_attr(
|
||||||
feature = "cargo-clippy",
|
feature = "cargo-clippy",
|
||||||
allow(
|
allow(
|
||||||
empty_line_after_outer_attr, missing_docs_in_private_items, redundant_field_names, stutter,
|
empty_line_after_outer_attr,
|
||||||
use_debug, use_self
|
missing_docs_in_private_items,
|
||||||
|
redundant_field_names,
|
||||||
|
stutter,
|
||||||
|
use_debug,
|
||||||
|
use_self
|
||||||
)
|
)
|
||||||
)]
|
)]
|
||||||
|
|
||||||
|
|||||||
@@ -29,8 +29,3 @@ fn run_mode(mode: &'static str) {
|
|||||||
fn compile_fail() {
|
fn compile_fail() {
|
||||||
run_mode("compile-fail");
|
run_mode("compile-fail");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn run_pass() {
|
|
||||||
run_mode("run-pass");
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,22 +0,0 @@
|
|||||||
// Copyright 2017 Serde Developers
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
||||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
||||||
// option. This file may not be copied, modified, or distributed
|
|
||||||
// except according to those terms.
|
|
||||||
|
|
||||||
#![deny(identity_op)]
|
|
||||||
|
|
||||||
#[macro_use]
|
|
||||||
extern crate serde_derive;
|
|
||||||
|
|
||||||
// The derived implementation uses 0+1 to add up the number of fields
|
|
||||||
// serialized, which Clippy warns about. If the expansion info is registered
|
|
||||||
// correctly, the Clippy lint is not triggered.
|
|
||||||
#[derive(Serialize)]
|
|
||||||
struct A {
|
|
||||||
b: u8,
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {}
|
|
||||||
@@ -348,7 +348,10 @@ struct ContainsNotDeserialize<A, B, C: DeserializeWith, E: MyDefault> {
|
|||||||
a: A,
|
a: A,
|
||||||
#[serde(skip_deserializing, default)]
|
#[serde(skip_deserializing, default)]
|
||||||
b: B,
|
b: B,
|
||||||
#[serde(deserialize_with = "DeserializeWith::deserialize_with", default)]
|
#[serde(
|
||||||
|
deserialize_with = "DeserializeWith::deserialize_with",
|
||||||
|
default
|
||||||
|
)]
|
||||||
c: C,
|
c: C,
|
||||||
#[serde(skip_deserializing, default = "MyDefault::my_default")]
|
#[serde(skip_deserializing, default = "MyDefault::my_default")]
|
||||||
e: E,
|
e: E,
|
||||||
|
|||||||
@@ -6,7 +6,10 @@
|
|||||||
// option. This file may not be copied, modified, or distributed
|
// option. This file may not be copied, modified, or distributed
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
#![cfg_attr(feature = "cargo-clippy", allow(decimal_literal_representation))]
|
#![cfg_attr(
|
||||||
|
feature = "cargo-clippy",
|
||||||
|
allow(decimal_literal_representation)
|
||||||
|
)]
|
||||||
#![cfg_attr(feature = "unstable", feature(never_type))]
|
#![cfg_attr(feature = "unstable", feature(never_type))]
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
@@ -215,9 +218,9 @@ fn assert_de_tokens_ignore(ignorable_tokens: &[Token]) {
|
|||||||
Token::I32(1),
|
Token::I32(1),
|
||||||
Token::Str("ignored"),
|
Token::Str("ignored"),
|
||||||
].into_iter()
|
].into_iter()
|
||||||
.chain(ignorable_tokens.to_vec().into_iter())
|
.chain(ignorable_tokens.to_vec().into_iter())
|
||||||
.chain(vec![Token::MapEnd].into_iter())
|
.chain(vec![Token::MapEnd].into_iter())
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let mut de = serde_test::Deserializer::new(&concated_tokens);
|
let mut de = serde_test::Deserializer::new(&concated_tokens);
|
||||||
let base = IgnoreBase::deserialize(&mut de).unwrap();
|
let base = IgnoreBase::deserialize(&mut de).unwrap();
|
||||||
@@ -808,6 +811,23 @@ declare_tests! {
|
|||||||
Token::SeqEnd,
|
Token::SeqEnd,
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
|
test_range_inclusive {
|
||||||
|
1u32..=2u32 => &[
|
||||||
|
Token::Struct { name: "RangeInclusive", len: 2 },
|
||||||
|
Token::Str("start"),
|
||||||
|
Token::U32(1),
|
||||||
|
|
||||||
|
Token::Str("end"),
|
||||||
|
Token::U32(2),
|
||||||
|
Token::StructEnd,
|
||||||
|
],
|
||||||
|
1u32..=2u32 => &[
|
||||||
|
Token::Seq { len: Some(2) },
|
||||||
|
Token::U64(1),
|
||||||
|
Token::U64(2),
|
||||||
|
Token::SeqEnd,
|
||||||
|
],
|
||||||
|
}
|
||||||
test_path {
|
test_path {
|
||||||
Path::new("/usr/local/lib") => &[
|
Path::new("/usr/local/lib") => &[
|
||||||
Token::BorrowedStr("/usr/local/lib"),
|
Token::BorrowedStr("/usr/local/lib"),
|
||||||
|
|||||||
@@ -198,7 +198,12 @@ fn test_gen() {
|
|||||||
assert::<WithTraits1<X, X>>();
|
assert::<WithTraits1<X, X>>();
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Serialize, Deserialize)]
|
||||||
#[serde(bound(serialize = "D: SerializeWith", deserialize = "D: DeserializeWith"))]
|
#[serde(
|
||||||
|
bound(
|
||||||
|
serialize = "D: SerializeWith",
|
||||||
|
deserialize = "D: DeserializeWith"
|
||||||
|
)
|
||||||
|
)]
|
||||||
struct WithTraits2<D, E> {
|
struct WithTraits2<D, E> {
|
||||||
#[serde(
|
#[serde(
|
||||||
serialize_with = "SerializeWith::serialize_with",
|
serialize_with = "SerializeWith::serialize_with",
|
||||||
@@ -206,7 +211,8 @@ fn test_gen() {
|
|||||||
)]
|
)]
|
||||||
d: D,
|
d: D,
|
||||||
#[serde(
|
#[serde(
|
||||||
serialize_with = "SerializeWith::serialize_with", bound(serialize = "E: SerializeWith")
|
serialize_with = "SerializeWith::serialize_with",
|
||||||
|
bound(serialize = "E: SerializeWith")
|
||||||
)]
|
)]
|
||||||
#[serde(
|
#[serde(
|
||||||
deserialize_with = "DeserializeWith::deserialize_with",
|
deserialize_with = "DeserializeWith::deserialize_with",
|
||||||
@@ -234,7 +240,12 @@ fn test_gen() {
|
|||||||
assert::<VariantWithTraits1<X, X>>();
|
assert::<VariantWithTraits1<X, X>>();
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Serialize, Deserialize)]
|
||||||
#[serde(bound(serialize = "D: SerializeWith", deserialize = "D: DeserializeWith"))]
|
#[serde(
|
||||||
|
bound(
|
||||||
|
serialize = "D: SerializeWith",
|
||||||
|
deserialize = "D: DeserializeWith"
|
||||||
|
)
|
||||||
|
)]
|
||||||
enum VariantWithTraits2<D, E> {
|
enum VariantWithTraits2<D, E> {
|
||||||
#[serde(
|
#[serde(
|
||||||
serialize_with = "SerializeWith::serialize_with",
|
serialize_with = "SerializeWith::serialize_with",
|
||||||
@@ -242,7 +253,8 @@ fn test_gen() {
|
|||||||
)]
|
)]
|
||||||
D(D),
|
D(D),
|
||||||
#[serde(
|
#[serde(
|
||||||
serialize_with = "SerializeWith::serialize_with", bound(serialize = "E: SerializeWith")
|
serialize_with = "SerializeWith::serialize_with",
|
||||||
|
bound(serialize = "E: SerializeWith")
|
||||||
)]
|
)]
|
||||||
#[serde(
|
#[serde(
|
||||||
deserialize_with = "DeserializeWith::deserialize_with",
|
deserialize_with = "DeserializeWith::deserialize_with",
|
||||||
|
|||||||
@@ -377,6 +377,17 @@ declare_tests! {
|
|||||||
Token::StructEnd,
|
Token::StructEnd,
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
|
test_range_inclusive {
|
||||||
|
1u32..=2u32 => &[
|
||||||
|
Token::Struct { name: "RangeInclusive", len: 2 },
|
||||||
|
Token::Str("start"),
|
||||||
|
Token::U32(1),
|
||||||
|
|
||||||
|
Token::Str("end"),
|
||||||
|
Token::U32(2),
|
||||||
|
Token::StructEnd,
|
||||||
|
],
|
||||||
|
}
|
||||||
test_path {
|
test_path {
|
||||||
Path::new("/usr/local/lib") => &[
|
Path::new("/usr/local/lib") => &[
|
||||||
Token::Str("/usr/local/lib"),
|
Token::Str("/usr/local/lib"),
|
||||||
|
|||||||
Reference in New Issue
Block a user