Compare commits

...

32 Commits

Author SHA1 Message Date
David Tolnay 24c4df7831 Release 1.0.71 2018-08-06 23:55:55 -07:00
David Tolnay a077ae039e Merge pull request #1349 from dtolnay/range
Share some code between the Range and RangeInclusive impls
2018-08-06 23:30:03 -07:00
David Tolnay 20b34d3b43 Share some code between the Range and RangeInclusive impls 2018-08-06 23:16:47 -07:00
David Tolnay b5451d1905 Merge pull request #1348 from dtolnay/range
Provide ops::Range impls whether or not std is used
2018-08-06 23:04:26 -07:00
David Tolnay e26960f7f8 Remove useless run-pass test
When originally added, this test used to contain a `#![plugin(clippy)]`.
This was removed at some point along the way, at which point this test
no longer tests anything. It prints:

    warning: unknown lint: `identity_op`
     --> src/main.rs:1:9
      |
    1 | #![deny(identity_op)]
      |         ^^^^^^^^^^^
      |
      = note: #[warn(unknown_lints)] on by default

which is swallowed and ignored by compiletest.

Nowadays Clippy handles warnings inside of macro expanded code
intelligently and this is something they would be responsible for
testing.
2018-08-06 22:57:46 -07:00
David Tolnay 228b5a4a63 Provide ops::Range impls whether or not std is used 2018-08-06 22:49:09 -07:00
David Tolnay 28db9d4989 Format with rustfmt 0.99.1 2018-08-06 22:40:28 -07:00
David Tolnay 5fff0d936d Merge pull request #1347 from c410-f3r/master
Implement Serialize and Deserialize for RangeInclusive
2018-08-06 22:36:12 -07:00
Caio 8eb195edf0 Fix tests 2018-08-05 17:38:41 -03:00
Caio 8b2e6baf78 Implement Serialize and Deserialize for RangeInclusive 2018-08-05 10:45:50 -03:00
David Tolnay 4e54aaf796 Format with rustfmt 0.8.2 2018-07-08 19:02:44 -07:00
David Tolnay 4cddcbe194 Release 1.0.70 2018-07-06 20:21:26 -07:00
David Tolnay 54b6798ef6 Merge pull request #1336 from dtolnay/collections
Update path to alloc::collections for nightly-2018-07-07
2018-07-06 20:19:59 -07:00
David Tolnay 229a9d90ba Update path to alloc::collections for nightly-2018-07-07 2018-07-06 20:04:23 -07:00
David Tolnay 3bcd568c86 Release 1.0.69 2018-06-30 23:40:28 -07:00
David Tolnay dc56077aac Local inner macros 2018-06-30 23:38:14 -07:00
David Tolnay 46bd36e17c Link to issue picker 2018-06-30 10:30:14 -07:00
David Tolnay 5dee9118c7 Factor out the getting help links 2018-06-30 10:29:36 -07:00
David Tolnay a916aa9420 Release 1.0.68 2018-06-28 09:31:12 -07:00
David Tolnay d9c63d0784 Merge pull request #1324 from jechase/suppress_2018_warning
Suppress 'extern crate' warning for rust 2018
2018-06-28 09:30:40 -07:00
Josh Chase 41dcb969e8 Shut clippy up 2018-06-28 11:12:27 -04:00
Josh Chase 6dbaea34ba Suppress 'extern crate' warning for rust 2018 2018-06-28 10:51:57 -04:00
David Tolnay ce17301b8b Release 1.0.67 2018-06-27 00:18:03 -07:00
David Tolnay b0e78c6be4 Format with rustfmt 0.8.2 2018-06-27 00:16:06 -07:00
David Tolnay 898f65fa46 Merge pull request #1323 from dtolnay/format-args
Implement Serialize for core::fmt::Arguments
2018-06-27 00:15:55 -07:00
David Tolnay 84e384196d Implement Serialize for core::fmt::Arguments 2018-06-26 23:58:16 -07:00
David Tolnay d827b101d9 Resolve default_trait_access lint 2018-06-26 23:58:02 -07:00
David Tolnay c45ab6b304 Ignore indexing_slicing pedantic lint 2018-06-26 23:56:39 -07:00
David Tolnay cc9d85b293 Work around unused_imports rustdoc bug 2018-06-26 23:54:32 -07:00
David Tolnay 02493d83be Ignore indexing_slicing pedantic lint 2018-06-26 23:39:26 -07:00
David Tolnay a1280c672a Switch no-std panic to #[panic_implementation] 2018-06-04 10:13:29 -07:00
David Tolnay a740f76772 Update no-std panic signature for nightly-2018-06-03 2018-06-03 23:15:16 -07:00
29 changed files with 404 additions and 261 deletions
+7 -6
View File
@@ -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
View File
@@ -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
View File
@@ -1,6 +1,6 @@
[package] [package]
name = "serde" name = "serde"
version = "1.0.66" # 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"
+6
View File
@@ -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
View File
@@ -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))
}
} }
} }
+2 -5
View File
@@ -97,6 +97,7 @@
//! - Path //! - Path
//! - PathBuf //! - PathBuf
//! - Range\<T\> //! - Range\<T\>
//! - RangeInclusive\<T\>
//! - num::NonZero* //! - num::NonZero*
//! - `!` *(unstable)* //! - `!` *(unstable)*
//! - **Net types**: //! - **Net types**:
@@ -593,11 +594,7 @@ pub trait Deserialize<'de>: Sized {
/// ///
/// [Understanding deserializer lifetimes]: https://serde.rs/lifetimes.html /// [Understanding deserializer lifetimes]: https://serde.rs/lifetimes.html
pub trait DeserializeOwned: for<'de> Deserialize<'de> {} pub trait DeserializeOwned: for<'de> Deserialize<'de> {}
impl<T> DeserializeOwned for T impl<T> DeserializeOwned for T where T: for<'de> Deserialize<'de> {}
where
T: for<'de> Deserialize<'de>,
{
}
/// `DeserializeSeed` is the stateful form of the `Deserialize` trait. If you /// `DeserializeSeed` is the stateful form of the `Deserialize` trait. If you
/// ever find yourself looking for a way to pass data into a `Deserialize` impl, /// ever find yourself looking for a way to pass data into a `Deserialize` impl,
+21 -6
View File
@@ -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.66")] #![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
@@ -118,6 +125,7 @@
stutter, stutter,
use_self, use_self,
// not practical // not practical
indexing_slicing,
many_single_char_names, many_single_char_names,
missing_docs_in_private_items, missing_docs_in_private_items,
similar_names, similar_names,
@@ -126,7 +134,10 @@
use_debug, use_debug,
))] ))]
// Blacklisted Rust lints. // Blacklisted Rust lints.
#![deny(missing_docs, unused_imports)] //
// Compiler bug involving unused_imports:
// https://github.com/rust-lang/rust/issues/51661
#![deny(missing_docs, /*unused_imports*/)]
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@@ -144,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};
@@ -155,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};
@@ -189,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};
@@ -215,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
View File
@@ -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>()}
+2 -2
View File
@@ -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);
+29 -2
View File
@@ -69,6 +69,15 @@ impl Serialize for String {
} }
} }
impl<'a> Serialize for fmt::Arguments<'a> {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
serializer.collect_str(self)
}
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
#[cfg(feature = "std")] #[cfg(feature = "std")]
@@ -218,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,
{ {
@@ -237,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>
+1
View File
@@ -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 -1
View File
@@ -1,6 +1,6 @@
[package] [package]
name = "serde_derive" name = "serde_derive"
version = "1.0.66" # 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)]"
+11 -15
View File
@@ -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,14 +192,13 @@ 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,
// the type parameter that is being bounded e.g. T // the type parameter that is being bounded e.g. T
bounded_ty: syn::Type::Path(bounded_ty), bounded_ty: syn::Type::Path(bounded_ty),
colon_token: Default::default(), colon_token: <Token![:]>::default(),
// the bound e.g. Serialize // the bound e.g. Serialize
bounds: vec![syn::TypeParamBound::Trait(syn::TraitBound { bounds: vec![syn::TypeParamBound::Trait(syn::TraitBound {
paren_token: None, paren_token: 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(),
}) })
}); });
@@ -233,7 +231,7 @@ pub fn with_self_bound(
lifetimes: None, lifetimes: None,
// the type that is being bounded e.g. MyStruct<'a, T> // the type that is being bounded e.g. MyStruct<'a, T>
bounded_ty: type_of_item(cont), bounded_ty: type_of_item(cont),
colon_token: Default::default(), colon_token: <Token![:]>::default(),
// the bound e.g. Default // the bound e.g. Default
bounds: vec![syn::TypeParamBound::Trait(syn::TraitBound { bounds: vec![syn::TypeParamBound::Trait(syn::TraitBound {
paren_token: None, paren_token: None,
@@ -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,
@@ -289,7 +286,7 @@ fn type_of_item(cont: &Container) -> syn::Type {
arguments: syn::PathArguments::AngleBracketed( arguments: syn::PathArguments::AngleBracketed(
syn::AngleBracketedGenericArguments { syn::AngleBracketedGenericArguments {
colon2_token: None, colon2_token: None,
lt_token: Default::default(), lt_token: <Token![<]>::default(),
args: cont args: cont
.generics .generics
.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: Default::default(),
}, },
), ),
}].into_iter() }].into_iter()
.collect(), .collect(),
}, },
}) })
} }
+8 -5
View File
@@ -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);
+2 -4
View File
@@ -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
View File
@@ -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.66")] #![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 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.
+1 -2
View File
@@ -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
View File
@@ -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,
+6 -1
View File
@@ -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 -1
View File
@@ -1,6 +1,6 @@
[package] [package]
name = "serde_test" name = "serde_test"
version = "1.0.66" # 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"
+2 -1
View File
@@ -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 })
} }
+7 -3
View File
@@ -161,7 +161,7 @@
//! # } //! # }
//! ``` //! ```
#![doc(html_root_url = "https://docs.rs/serde_test/1.0.66")] #![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
) )
)] )]
+3 -8
View File
@@ -6,7 +6,7 @@
// 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.
#![feature(lang_items, start)] #![feature(lang_items, start, panic_implementation)]
#![no_std] #![no_std]
extern crate libc; extern crate libc;
@@ -20,13 +20,8 @@ fn start(_argc: isize, _argv: *const *const u8) -> isize {
#[no_mangle] #[no_mangle]
pub extern "C" fn rust_eh_personality() {} pub extern "C" fn rust_eh_personality() {}
#[lang = "panic_fmt"] #[panic_implementation]
#[no_mangle] fn panic(_info: &core::panic::PanicInfo) -> ! {
pub extern "C" fn rust_begin_panic(
_msg: core::fmt::Arguments,
_file: &'static str,
_line: u32,
) -> ! {
unsafe { unsafe {
libc::abort(); libc::abort();
} }
-5
View File
@@ -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");
}
-22
View File
@@ -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() {}
+4 -1
View File
@@ -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,
+24 -4
View File
@@ -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"),
+16 -4
View File
@@ -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",
+16
View File
@@ -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"),
@@ -462,6 +473,11 @@ declare_tests! {
Token::SeqEnd, Token::SeqEnd,
], ],
} }
test_fmt_arguments {
format_args!("{}{}", 1, 'a') => &[
Token::Str("1a"),
],
}
} }
declare_tests! { declare_tests! {