mirror of
https://github.com/pezkuwichain/serde.git
synced 2026-04-26 02:47:56 +00:00
Compare commits
57 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| bb99b31eb0 | |||
| 84397183f3 | |||
| aeae265777 | |||
| a9c5df5da1 | |||
| 96576c4de9 | |||
| 9ec68e5829 | |||
| face857d5e | |||
| 85a1cc9b4f | |||
| 630501b93d | |||
| 8bbc2995ca | |||
| 7d3872df57 | |||
| 1ed228b92b | |||
| b605cd1bb9 | |||
| fea4e8e5b6 | |||
| 1df8b5785b | |||
| 981a75d7c9 | |||
| 11cc7014b3 | |||
| 0b667c88fa | |||
| 054ab1adaf | |||
| f1f8386f2e | |||
| ba8c3970b0 | |||
| 2f36b26a5c | |||
| 9b4edb3a1d | |||
| b8adc5ffa2 | |||
| bd90cafda7 | |||
| 6d43a08a1d | |||
| e71b8598ae | |||
| 95d0f437e3 | |||
| c95ee3968a | |||
| c22dd4ada5 | |||
| 727a40fc5a | |||
| ce84a5f1d3 | |||
| e6fda1c410 | |||
| 294dccc5be | |||
| da346a8878 | |||
| c5ccb995ad | |||
| 05ab569a80 | |||
| ab3f4971f0 | |||
| 47e238aa13 | |||
| e49b6c708b | |||
| eb7250792b | |||
| 7e5066b878 | |||
| 889e17816f | |||
| b1b9702daf | |||
| 32728d2f1d | |||
| 807a097387 | |||
| 794ee15386 | |||
| 2359417804 | |||
| 7950f3cdc5 | |||
| b87f8f35ee | |||
| 9e53405f43 | |||
| c6c1d8fa86 | |||
| 8aa5c2b45d | |||
| 414fd694c0 | |||
| 7e82809592 | |||
| 0dae5db30e | |||
| 5c24f0f0f3 |
+9
-9
@@ -9,7 +9,7 @@ matrix:
|
|||||||
- cargo build --no-default-features
|
- cargo build --no-default-features
|
||||||
- cd "${TRAVIS_BUILD_DIR}/serde_test"
|
- cd "${TRAVIS_BUILD_DIR}/serde_test"
|
||||||
- cargo build
|
- cargo build
|
||||||
- cargo test
|
- cargo test --features serde/derive,serde/rc
|
||||||
|
|
||||||
- rust: beta
|
- rust: beta
|
||||||
script:
|
script:
|
||||||
@@ -25,11 +25,11 @@ matrix:
|
|||||||
- cargo build --no-default-features
|
- cargo build --no-default-features
|
||||||
- cargo build --no-default-features --features alloc
|
- cargo build --no-default-features --features alloc
|
||||||
- cargo build --no-default-features --features rc,alloc
|
- cargo build --no-default-features --features rc,alloc
|
||||||
- cargo test --features rc,unstable
|
- cargo test --features derive,rc,unstable
|
||||||
- cd "${TRAVIS_BUILD_DIR}/test_suite/deps"
|
- cd "${TRAVIS_BUILD_DIR}/test_suite/deps"
|
||||||
- cargo build
|
- cargo build
|
||||||
- cd "${TRAVIS_BUILD_DIR}/test_suite"
|
- cd "${TRAVIS_BUILD_DIR}/test_suite"
|
||||||
- cargo test --features unstable
|
- cargo test --features compiletest,unstable
|
||||||
- cd "${TRAVIS_BUILD_DIR}/test_suite/no_std"
|
- cd "${TRAVIS_BUILD_DIR}/test_suite/no_std"
|
||||||
- cargo build
|
- cargo build
|
||||||
|
|
||||||
@@ -55,17 +55,17 @@ matrix:
|
|||||||
name: Clippy
|
name: Clippy
|
||||||
script:
|
script:
|
||||||
- rustup component add clippy-preview || travis_terminate 0
|
- rustup component add clippy-preview || travis_terminate 0
|
||||||
- cargo clippy -- -Dclippy
|
- cargo clippy -- -D clippy::all
|
||||||
- cd "${TRAVIS_BUILD_DIR}/serde"
|
- cd "${TRAVIS_BUILD_DIR}/serde"
|
||||||
- cargo clippy --features rc,unstable -- -Dclippy
|
- cargo clippy --features rc,unstable -- -D clippy::all
|
||||||
- cd "${TRAVIS_BUILD_DIR}/serde_derive"
|
- cd "${TRAVIS_BUILD_DIR}/serde_derive"
|
||||||
- cargo clippy -- -Dclippy
|
- cargo clippy -- -D clippy::all
|
||||||
- cd "${TRAVIS_BUILD_DIR}/serde_test"
|
- cd "${TRAVIS_BUILD_DIR}/serde_test"
|
||||||
- cargo clippy -- -Dclippy
|
- cargo clippy -- -D clippy::all
|
||||||
- cd "${TRAVIS_BUILD_DIR}/test_suite"
|
- cd "${TRAVIS_BUILD_DIR}/test_suite"
|
||||||
- cargo clippy --features unstable -- -Dclippy
|
- cargo clippy --tests --features unstable -- -D clippy::all
|
||||||
- cd "${TRAVIS_BUILD_DIR}/test_suite/no_std"
|
- cd "${TRAVIS_BUILD_DIR}/test_suite/no_std"
|
||||||
- cargo clippy -- -Dclippy
|
- cargo clippy -- -D clippy::all
|
||||||
|
|
||||||
- rust: nightly
|
- rust: nightly
|
||||||
name: Emscripten
|
name: Emscripten
|
||||||
|
|||||||
@@ -25,19 +25,17 @@ You may be looking for:
|
|||||||
<details>
|
<details>
|
||||||
<summary>
|
<summary>
|
||||||
Click to show Cargo.toml.
|
Click to show Cargo.toml.
|
||||||
<a href="https://play.rust-lang.org/?gist=9003c5b88c1f4989941925d7190c6eec" target="_blank">Run this code in the playground.</a>
|
<a href="https://play.rust-lang.org/?edition=2018&gist=72755f28f99afc95e01d63174b28c1f5" target="_blank">Run this code in the playground.</a>
|
||||||
</summary>
|
</summary>
|
||||||
|
|
||||||
```toml
|
```toml
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|
||||||
# The core APIs, including the Serialize and Deserialize traits. Always
|
# The core APIs, including the Serialize and Deserialize traits. Always
|
||||||
# required when using Serde.
|
# required when using Serde. The "derive" feature is only required when
|
||||||
serde = "1.0"
|
# using #[derive(Serialize, Deserialize)] to make Serde work with structs
|
||||||
|
# and enums defined in your crate.
|
||||||
# Support for #[derive(Serialize, Deserialize)]. Required if you want Serde
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
# to work for structs and enums defined in your crate.
|
|
||||||
serde_derive = "1.0"
|
|
||||||
|
|
||||||
# Each data format lives in its own crate; the sample code below uses JSON
|
# Each data format lives in its own crate; the sample code below uses JSON
|
||||||
# but you may be using a different one.
|
# but you may be using a different one.
|
||||||
@@ -48,11 +46,7 @@ serde_json = "1.0"
|
|||||||
<p></p>
|
<p></p>
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
#[macro_use]
|
use serde::{Serialize, Deserialize};
|
||||||
extern crate serde_derive;
|
|
||||||
|
|
||||||
extern crate serde;
|
|
||||||
extern crate serde_json;
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug)]
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
struct Point {
|
struct Point {
|
||||||
|
|||||||
+3
-3
@@ -23,7 +23,7 @@ for:
|
|||||||
- cargo build --no-default-features
|
- cargo build --no-default-features
|
||||||
- cd %APPVEYOR_BUILD_FOLDER%\serde_test
|
- cd %APPVEYOR_BUILD_FOLDER%\serde_test
|
||||||
- cargo build
|
- cargo build
|
||||||
- cargo test
|
- cargo test --features serde/derive,serde/rc
|
||||||
|
|
||||||
- matrix:
|
- matrix:
|
||||||
only:
|
only:
|
||||||
@@ -34,8 +34,8 @@ for:
|
|||||||
- cargo build --no-default-features
|
- cargo build --no-default-features
|
||||||
- cargo build --no-default-features --features alloc
|
- cargo build --no-default-features --features alloc
|
||||||
- cargo build --no-default-features --features rc,alloc
|
- cargo build --no-default-features --features rc,alloc
|
||||||
- cargo test --features rc,unstable
|
- cargo test --features derive,rc,unstable
|
||||||
- cd %APPVEYOR_BUILD_FOLDER%\test_suite\deps
|
- cd %APPVEYOR_BUILD_FOLDER%\test_suite\deps
|
||||||
- cargo build
|
- cargo build
|
||||||
- cd %APPVEYOR_BUILD_FOLDER%\test_suite
|
- cd %APPVEYOR_BUILD_FOLDER%\test_suite
|
||||||
- cargo test --features unstable
|
- cargo test --features compiletest,unstable
|
||||||
|
|||||||
+1
-5
@@ -16,11 +16,7 @@ You may be looking for:
|
|||||||
## Serde in action
|
## Serde in action
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
#[macro_use]
|
use serde::{Serialize, Deserialize};
|
||||||
extern crate serde_derive;
|
|
||||||
|
|
||||||
extern crate serde;
|
|
||||||
extern crate serde_json;
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug)]
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
struct Point {
|
struct Point {
|
||||||
|
|||||||
+5
-25
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "serde"
|
name = "serde"
|
||||||
version = "1.0.82" # remember to update html_root_url
|
version = "1.0.85" # 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"
|
||||||
@@ -23,36 +23,16 @@ serde_derive = { version = "1.0", optional = true, path = "../serde_derive" }
|
|||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
serde_derive = { version = "1.0", path = "../serde_derive" }
|
serde_derive = { version = "1.0", path = "../serde_derive" }
|
||||||
|
|
||||||
|
[package.metadata.playground]
|
||||||
|
features = ["derive", "rc"]
|
||||||
|
|
||||||
|
|
||||||
### FEATURES #################################################################
|
### FEATURES #################################################################
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["std"]
|
default = ["std"]
|
||||||
|
|
||||||
# Re-export the derive(Serialize, Deserialize) macros. This is intended for
|
# Provide derive(Serialize, Deserialize) macros.
|
||||||
# library crates that provide optional Serde impls behind a Cargo cfg of their
|
|
||||||
# own.
|
|
||||||
#
|
|
||||||
# Mainly this is a workaround for limitations associated with
|
|
||||||
# rust-lang/cargo#1286 in which a library crate cannot use one "serde" cfg in
|
|
||||||
# Cargo to enable dependencies on both serde and serde_derive crates.
|
|
||||||
#
|
|
||||||
# The recommended way to provide optional Serde support that requires derive is
|
|
||||||
# as follows. In particular, please do not name your library's Serde feature
|
|
||||||
# anything other than "serde".
|
|
||||||
#
|
|
||||||
# [dependencies]
|
|
||||||
# serde = { version = "1.0", optional = true, features = ["derive"] }
|
|
||||||
#
|
|
||||||
# Within the library, these optional Serde derives would be written like this.
|
|
||||||
#
|
|
||||||
# #[cfg(feature = "serde")]
|
|
||||||
# #[macro_use]
|
|
||||||
# extern crate serde;
|
|
||||||
#
|
|
||||||
# #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
|
||||||
# struct ...
|
|
||||||
#
|
|
||||||
derive = ["serde_derive"]
|
derive = ["serde_derive"]
|
||||||
|
|
||||||
# Provide impls for common standard library types like Vec<T> and HashMap<K, V>.
|
# Provide impls for common standard library types like Vec<T> and HashMap<K, V>.
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ use de::{Deserialize, Deserializer, Error, MapAccess, SeqAccess, Visitor};
|
|||||||
/// any type, except that it does not store any information about the data that
|
/// any type, except that it does not store any information about the data that
|
||||||
/// gets deserialized.
|
/// gets deserialized.
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```edition2018
|
||||||
/// use std::fmt;
|
/// use std::fmt;
|
||||||
/// use std::marker::PhantomData;
|
/// use std::marker::PhantomData;
|
||||||
///
|
///
|
||||||
@@ -21,7 +21,7 @@ use de::{Deserialize, Deserializer, Error, MapAccess, SeqAccess, Visitor};
|
|||||||
/// ///
|
/// ///
|
||||||
/// /// For example to deserialize only the element at index 3:
|
/// /// For example to deserialize only the element at index 3:
|
||||||
/// ///
|
/// ///
|
||||||
/// /// ```rust
|
/// /// ```
|
||||||
/// /// NthElement::new(3).deserialize(deserializer)
|
/// /// NthElement::new(3).deserialize(deserializer)
|
||||||
/// /// ```
|
/// /// ```
|
||||||
/// pub struct NthElement<T> {
|
/// pub struct NthElement<T> {
|
||||||
|
|||||||
+37
-35
@@ -153,7 +153,7 @@ macro_rules! declare_error_trait {
|
|||||||
///
|
///
|
||||||
/// The message should not be capitalized and should not end with a period.
|
/// The message should not be capitalized and should not end with a period.
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```edition2018
|
||||||
/// # use std::str::FromStr;
|
/// # use std::str::FromStr;
|
||||||
/// #
|
/// #
|
||||||
/// # struct IpAddr;
|
/// # struct IpAddr;
|
||||||
@@ -173,7 +173,7 @@ macro_rules! declare_error_trait {
|
|||||||
/// where
|
/// where
|
||||||
/// D: Deserializer<'de>,
|
/// D: Deserializer<'de>,
|
||||||
/// {
|
/// {
|
||||||
/// let s = try!(String::deserialize(deserializer));
|
/// let s = String::deserialize(deserializer)?;
|
||||||
/// s.parse().map_err(de::Error::custom)
|
/// s.parse().map_err(de::Error::custom)
|
||||||
/// }
|
/// }
|
||||||
/// }
|
/// }
|
||||||
@@ -237,12 +237,16 @@ macro_rules! declare_error_trait {
|
|||||||
#[cold]
|
#[cold]
|
||||||
fn unknown_variant(variant: &str, expected: &'static [&'static str]) -> Self {
|
fn unknown_variant(variant: &str, expected: &'static [&'static str]) -> Self {
|
||||||
if expected.is_empty() {
|
if expected.is_empty() {
|
||||||
Error::custom(format_args!("unknown variant `{}`, there are no variants",
|
Error::custom(format_args!(
|
||||||
variant))
|
"unknown variant `{}`, there are no variants",
|
||||||
|
variant
|
||||||
|
))
|
||||||
} else {
|
} else {
|
||||||
Error::custom(format_args!("unknown variant `{}`, expected {}",
|
Error::custom(format_args!(
|
||||||
variant,
|
"unknown variant `{}`, expected {}",
|
||||||
OneOf { names: expected }))
|
variant,
|
||||||
|
OneOf { names: expected }
|
||||||
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -251,12 +255,16 @@ macro_rules! declare_error_trait {
|
|||||||
#[cold]
|
#[cold]
|
||||||
fn unknown_field(field: &str, expected: &'static [&'static str]) -> Self {
|
fn unknown_field(field: &str, expected: &'static [&'static str]) -> Self {
|
||||||
if expected.is_empty() {
|
if expected.is_empty() {
|
||||||
Error::custom(format_args!("unknown field `{}`, there are no fields",
|
Error::custom(format_args!(
|
||||||
field))
|
"unknown field `{}`, there are no fields",
|
||||||
|
field
|
||||||
|
))
|
||||||
} else {
|
} else {
|
||||||
Error::custom(format_args!("unknown field `{}`, expected {}",
|
Error::custom(format_args!(
|
||||||
field,
|
"unknown field `{}`, expected {}",
|
||||||
OneOf { names: expected }))
|
field,
|
||||||
|
OneOf { names: expected }
|
||||||
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -290,7 +298,7 @@ declare_error_trait!(Error: Sized + Debug + Display);
|
|||||||
/// This is used as an argument to the `invalid_type`, `invalid_value`, and
|
/// This is used as an argument to the `invalid_type`, `invalid_value`, and
|
||||||
/// `invalid_length` methods of the `Error` trait to build error messages.
|
/// `invalid_length` methods of the `Error` trait to build error messages.
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```edition2018
|
||||||
/// # use std::fmt;
|
/// # use std::fmt;
|
||||||
/// #
|
/// #
|
||||||
/// # use serde::de::{self, Unexpected, Visitor};
|
/// # use serde::de::{self, Unexpected, Visitor};
|
||||||
@@ -415,7 +423,7 @@ impl<'a> fmt::Display for Unexpected<'a> {
|
|||||||
/// Within the context of a `Visitor` implementation, the `Visitor` itself
|
/// Within the context of a `Visitor` implementation, the `Visitor` itself
|
||||||
/// (`&self`) is an implementation of this trait.
|
/// (`&self`) is an implementation of this trait.
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```edition2018
|
||||||
/// # use std::fmt;
|
/// # use std::fmt;
|
||||||
/// #
|
/// #
|
||||||
/// # use serde::de::{self, Unexpected, Visitor};
|
/// # use serde::de::{self, Unexpected, Visitor};
|
||||||
@@ -440,7 +448,7 @@ impl<'a> fmt::Display for Unexpected<'a> {
|
|||||||
///
|
///
|
||||||
/// Outside of a `Visitor`, `&"..."` can be used.
|
/// Outside of a `Visitor`, `&"..."` can be used.
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```edition2018
|
||||||
/// # use serde::de::{self, Unexpected};
|
/// # use serde::de::{self, Unexpected};
|
||||||
/// #
|
/// #
|
||||||
/// # fn example<E>() -> Result<(), E>
|
/// # fn example<E>() -> Result<(), E>
|
||||||
@@ -561,7 +569,7 @@ pub trait Deserialize<'de>: Sized {
|
|||||||
/// from the input string, but a `from_reader` function may only deserialize
|
/// from the input string, but a `from_reader` function may only deserialize
|
||||||
/// owned data.
|
/// owned data.
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```edition2018
|
||||||
/// # use serde::de::{Deserialize, DeserializeOwned};
|
/// # use serde::de::{Deserialize, DeserializeOwned};
|
||||||
/// # use std::io::{Read, Result};
|
/// # use std::io::{Read, Result};
|
||||||
/// #
|
/// #
|
||||||
@@ -600,7 +608,7 @@ impl<T> DeserializeOwned for T where T: for<'de> Deserialize<'de> {}
|
|||||||
///
|
///
|
||||||
/// The canonical API for stateless deserialization looks like this:
|
/// The canonical API for stateless deserialization looks like this:
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```edition2018
|
||||||
/// # use serde::Deserialize;
|
/// # use serde::Deserialize;
|
||||||
/// #
|
/// #
|
||||||
/// # enum Error {}
|
/// # enum Error {}
|
||||||
@@ -614,7 +622,7 @@ impl<T> DeserializeOwned for T where T: for<'de> Deserialize<'de> {}
|
|||||||
/// Adjusting an API like this to support stateful deserialization is a matter
|
/// Adjusting an API like this to support stateful deserialization is a matter
|
||||||
/// of accepting a seed as input:
|
/// of accepting a seed as input:
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```edition2018
|
||||||
/// # use serde::de::DeserializeSeed;
|
/// # use serde::de::DeserializeSeed;
|
||||||
/// #
|
/// #
|
||||||
/// # enum Error {}
|
/// # enum Error {}
|
||||||
@@ -647,7 +655,7 @@ impl<T> DeserializeOwned for T where T: for<'de> Deserialize<'de> {}
|
|||||||
/// into it. This requires stateful deserialization using the `DeserializeSeed`
|
/// into it. This requires stateful deserialization using the `DeserializeSeed`
|
||||||
/// trait.
|
/// trait.
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```edition2018
|
||||||
/// use std::fmt;
|
/// use std::fmt;
|
||||||
/// use std::marker::PhantomData;
|
/// use std::marker::PhantomData;
|
||||||
///
|
///
|
||||||
@@ -1137,7 +1145,7 @@ pub trait Deserializer<'de>: Sized {
|
|||||||
/// human-readable one and binary formats like Bincode will prefer the
|
/// human-readable one and binary formats like Bincode will prefer the
|
||||||
/// compact one.
|
/// compact one.
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```edition2018
|
||||||
/// # use std::ops::Add;
|
/// # use std::ops::Add;
|
||||||
/// # use std::str::FromStr;
|
/// # use std::str::FromStr;
|
||||||
/// #
|
/// #
|
||||||
@@ -1214,7 +1222,7 @@ pub trait Deserializer<'de>: Sized {
|
|||||||
///
|
///
|
||||||
/// # Example
|
/// # Example
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```edition2018
|
||||||
/// # use std::fmt;
|
/// # use std::fmt;
|
||||||
/// #
|
/// #
|
||||||
/// # use serde::de::{self, Unexpected, Visitor};
|
/// # use serde::de::{self, Unexpected, Visitor};
|
||||||
@@ -1255,7 +1263,7 @@ pub trait Visitor<'de>: Sized {
|
|||||||
/// "an integer between 0 and 64". The message should not be capitalized and
|
/// "an integer between 0 and 64". The message should not be capitalized and
|
||||||
/// should not end with a period.
|
/// should not end with a period.
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```edition2018
|
||||||
/// # use std::fmt;
|
/// # use std::fmt;
|
||||||
/// #
|
/// #
|
||||||
/// # struct S {
|
/// # struct S {
|
||||||
@@ -1996,7 +2004,7 @@ pub trait VariantAccess<'de>: Sized {
|
|||||||
/// If the data contains a different type of variant, the following
|
/// If the data contains a different type of variant, the following
|
||||||
/// `invalid_type` error should be constructed:
|
/// `invalid_type` error should be constructed:
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```edition2018
|
||||||
/// # use serde::de::{self, value, DeserializeSeed, Visitor, VariantAccess, Unexpected};
|
/// # use serde::de::{self, value, DeserializeSeed, Visitor, VariantAccess, Unexpected};
|
||||||
/// #
|
/// #
|
||||||
/// # struct X;
|
/// # struct X;
|
||||||
@@ -2036,7 +2044,7 @@ pub trait VariantAccess<'de>: Sized {
|
|||||||
/// If the data contains a different type of variant, the following
|
/// If the data contains a different type of variant, the following
|
||||||
/// `invalid_type` error should be constructed:
|
/// `invalid_type` error should be constructed:
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```edition2018
|
||||||
/// # use serde::de::{self, value, DeserializeSeed, Visitor, VariantAccess, Unexpected};
|
/// # use serde::de::{self, value, DeserializeSeed, Visitor, VariantAccess, Unexpected};
|
||||||
/// #
|
/// #
|
||||||
/// # struct X;
|
/// # struct X;
|
||||||
@@ -2092,7 +2100,7 @@ pub trait VariantAccess<'de>: Sized {
|
|||||||
/// If the data contains a different type of variant, the following
|
/// If the data contains a different type of variant, the following
|
||||||
/// `invalid_type` error should be constructed:
|
/// `invalid_type` error should be constructed:
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```edition2018
|
||||||
/// # use serde::de::{self, value, DeserializeSeed, Visitor, VariantAccess, Unexpected};
|
/// # use serde::de::{self, value, DeserializeSeed, Visitor, VariantAccess, Unexpected};
|
||||||
/// #
|
/// #
|
||||||
/// # struct X;
|
/// # struct X;
|
||||||
@@ -2139,7 +2147,7 @@ pub trait VariantAccess<'de>: Sized {
|
|||||||
/// If the data contains a different type of variant, the following
|
/// If the data contains a different type of variant, the following
|
||||||
/// `invalid_type` error should be constructed:
|
/// `invalid_type` error should be constructed:
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```edition2018
|
||||||
/// # use serde::de::{self, value, DeserializeSeed, Visitor, VariantAccess, Unexpected};
|
/// # use serde::de::{self, value, DeserializeSeed, Visitor, VariantAccess, Unexpected};
|
||||||
/// #
|
/// #
|
||||||
/// # struct X;
|
/// # struct X;
|
||||||
@@ -2199,14 +2207,10 @@ pub trait VariantAccess<'de>: Sized {
|
|||||||
///
|
///
|
||||||
/// # Example
|
/// # Example
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```edition2018
|
||||||
/// #[macro_use]
|
|
||||||
/// extern crate serde_derive;
|
|
||||||
///
|
|
||||||
/// extern crate serde;
|
|
||||||
///
|
|
||||||
/// use std::str::FromStr;
|
/// use std::str::FromStr;
|
||||||
/// use serde::de::{value, Deserialize, IntoDeserializer};
|
/// use serde::Deserialize;
|
||||||
|
/// use serde::de::{value, IntoDeserializer};
|
||||||
///
|
///
|
||||||
/// #[derive(Deserialize)]
|
/// #[derive(Deserialize)]
|
||||||
/// enum Setting {
|
/// enum Setting {
|
||||||
@@ -2221,8 +2225,6 @@ pub trait VariantAccess<'de>: Sized {
|
|||||||
/// Self::deserialize(s.into_deserializer())
|
/// Self::deserialize(s.into_deserializer())
|
||||||
/// }
|
/// }
|
||||||
/// }
|
/// }
|
||||||
/// #
|
|
||||||
/// # fn main() {}
|
|
||||||
/// ```
|
/// ```
|
||||||
pub trait IntoDeserializer<'de, E: Error = value::Error> {
|
pub trait IntoDeserializer<'de, E: Error = value::Error> {
|
||||||
/// The type of the deserializer being converted into.
|
/// The type of the deserializer being converted into.
|
||||||
|
|||||||
@@ -1,14 +1,10 @@
|
|||||||
//! Building blocks for deserializing basic values using the `IntoDeserializer`
|
//! Building blocks for deserializing basic values using the `IntoDeserializer`
|
||||||
//! trait.
|
//! trait.
|
||||||
//!
|
//!
|
||||||
//! ```rust
|
//! ```edition2018
|
||||||
//! #[macro_use]
|
|
||||||
//! extern crate serde_derive;
|
|
||||||
//!
|
|
||||||
//! extern crate serde;
|
|
||||||
//!
|
|
||||||
//! use std::str::FromStr;
|
//! use std::str::FromStr;
|
||||||
//! use serde::de::{value, Deserialize, IntoDeserializer};
|
//! use serde::Deserialize;
|
||||||
|
//! use serde::de::{value, IntoDeserializer};
|
||||||
//!
|
//!
|
||||||
//! #[derive(Deserialize)]
|
//! #[derive(Deserialize)]
|
||||||
//! enum Setting {
|
//! enum Setting {
|
||||||
@@ -23,8 +19,6 @@
|
|||||||
//! Self::deserialize(s.into_deserializer())
|
//! Self::deserialize(s.into_deserializer())
|
||||||
//! }
|
//! }
|
||||||
//! }
|
//! }
|
||||||
//! #
|
|
||||||
//! # fn main() {}
|
|
||||||
//! ```
|
//! ```
|
||||||
|
|
||||||
use lib::*;
|
use lib::*;
|
||||||
|
|||||||
+6
-10
@@ -9,14 +9,12 @@
|
|||||||
/// do not need to bother with this macro and may assume support for 128-bit
|
/// do not need to bother with this macro and may assume support for 128-bit
|
||||||
/// integers.
|
/// integers.
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```edition2018
|
||||||
/// #[macro_use]
|
|
||||||
/// extern crate serde;
|
|
||||||
///
|
|
||||||
/// use serde::Serializer;
|
|
||||||
/// # use serde::private::ser::Error;
|
/// # use serde::private::ser::Error;
|
||||||
/// #
|
/// #
|
||||||
/// # struct MySerializer;
|
/// # struct MySerializer;
|
||||||
|
/// #
|
||||||
|
/// use serde::{serde_if_integer128, Serializer};
|
||||||
///
|
///
|
||||||
/// impl Serializer for MySerializer {
|
/// impl Serializer for MySerializer {
|
||||||
/// type Ok = ();
|
/// type Ok = ();
|
||||||
@@ -41,20 +39,18 @@
|
|||||||
/// }
|
/// }
|
||||||
/// }
|
/// }
|
||||||
/// #
|
/// #
|
||||||
/// # __serialize_unimplemented! {
|
/// # serde::__serialize_unimplemented! {
|
||||||
/// # bool i8 i16 i32 u8 u16 u32 u64 f32 f64 char str bytes none some
|
/// # bool i8 i16 i32 u8 u16 u32 u64 f32 f64 char str bytes none some
|
||||||
/// # unit unit_struct unit_variant newtype_struct newtype_variant seq
|
/// # unit unit_struct unit_variant newtype_struct newtype_variant seq
|
||||||
/// # tuple tuple_struct tuple_variant map struct struct_variant
|
/// # tuple tuple_struct tuple_variant map struct struct_variant
|
||||||
/// # }
|
/// # }
|
||||||
/// }
|
/// }
|
||||||
/// #
|
|
||||||
/// # fn main() {}
|
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// When Serde is built with support for 128-bit integers, this macro expands
|
/// When Serde is built with support for 128-bit integers, this macro expands
|
||||||
/// transparently into just the input tokens.
|
/// transparently into just the input tokens.
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```edition2018
|
||||||
/// macro_rules! serde_if_integer128 {
|
/// macro_rules! serde_if_integer128 {
|
||||||
/// ($($tt:tt)*) => {
|
/// ($($tt:tt)*) => {
|
||||||
/// $($tt)*
|
/// $($tt)*
|
||||||
@@ -65,7 +61,7 @@
|
|||||||
/// When built without support for 128-bit integers, this macro expands to
|
/// When built without support for 128-bit integers, this macro expands to
|
||||||
/// nothing.
|
/// nothing.
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```edition2018
|
||||||
/// macro_rules! serde_if_integer128 {
|
/// macro_rules! serde_if_integer128 {
|
||||||
/// ($($tt:tt)*) => {};
|
/// ($($tt:tt)*) => {};
|
||||||
/// }
|
/// }
|
||||||
|
|||||||
+4
-38
@@ -75,7 +75,7 @@
|
|||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
// Serde types in rustdoc of other crates get linked to here.
|
// Serde types in rustdoc of other crates get linked to here.
|
||||||
#![doc(html_root_url = "https://docs.rs/serde/1.0.82")]
|
#![doc(html_root_url = "https://docs.rs/serde/1.0.85")]
|
||||||
// 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
|
||||||
@@ -86,7 +86,7 @@
|
|||||||
#![cfg_attr(feature = "alloc", feature(alloc))]
|
#![cfg_attr(feature = "alloc", feature(alloc))]
|
||||||
#![cfg_attr(feature = "cargo-clippy", allow(renamed_and_removed_lints))]
|
#![cfg_attr(feature = "cargo-clippy", allow(renamed_and_removed_lints))]
|
||||||
#![cfg_attr(feature = "cargo-clippy", deny(clippy, clippy_pedantic))]
|
#![cfg_attr(feature = "cargo-clippy", deny(clippy, clippy_pedantic))]
|
||||||
// Whitelisted clippy lints
|
// Ignored clippy lints
|
||||||
#![cfg_attr(
|
#![cfg_attr(
|
||||||
feature = "cargo-clippy",
|
feature = "cargo-clippy",
|
||||||
allow(
|
allow(
|
||||||
@@ -101,7 +101,7 @@
|
|||||||
zero_prefixed_literal
|
zero_prefixed_literal
|
||||||
)
|
)
|
||||||
)]
|
)]
|
||||||
// Whitelisted clippy_pedantic lints
|
// Ignored clippy_pedantic lints
|
||||||
#![cfg_attr(feature = "cargo-clippy", allow(
|
#![cfg_attr(feature = "cargo-clippy", allow(
|
||||||
// integer and float ser/de requires these sorts of casts
|
// integer and float ser/de requires these sorts of casts
|
||||||
cast_possible_truncation,
|
cast_possible_truncation,
|
||||||
@@ -112,11 +112,11 @@
|
|||||||
invalid_upcast_comparisons,
|
invalid_upcast_comparisons,
|
||||||
// things are often more readable this way
|
// things are often more readable this way
|
||||||
decimal_literal_representation,
|
decimal_literal_representation,
|
||||||
|
module_name_repetitions,
|
||||||
option_unwrap_used,
|
option_unwrap_used,
|
||||||
result_unwrap_used,
|
result_unwrap_used,
|
||||||
shadow_reuse,
|
shadow_reuse,
|
||||||
single_match_else,
|
single_match_else,
|
||||||
stutter,
|
|
||||||
use_self,
|
use_self,
|
||||||
// not practical
|
// not practical
|
||||||
indexing_slicing,
|
indexing_slicing,
|
||||||
@@ -252,40 +252,6 @@ pub mod private;
|
|||||||
|
|
||||||
// Re-export #[derive(Serialize, Deserialize)].
|
// Re-export #[derive(Serialize, Deserialize)].
|
||||||
//
|
//
|
||||||
// This is a workaround for https://github.com/rust-lang/cargo/issues/1286.
|
|
||||||
// Without this re-export, crates that put Serde derives behind a cfg_attr would
|
|
||||||
// need to use some silly feature name that depends on both serde and
|
|
||||||
// serde_derive.
|
|
||||||
//
|
|
||||||
// [features]
|
|
||||||
// serde-impls = ["serde", "serde_derive"]
|
|
||||||
//
|
|
||||||
// [dependencies]
|
|
||||||
// serde = { version = "1.0", optional = true }
|
|
||||||
// serde_derive = { version = "1.0", optional = true }
|
|
||||||
//
|
|
||||||
// # Used like this:
|
|
||||||
// # #[cfg(feature = "serde-impls")]
|
|
||||||
// # #[macro_use]
|
|
||||||
// # extern crate serde_derive;
|
|
||||||
// #
|
|
||||||
// # #[cfg_attr(feature = "serde-impls", derive(Serialize, Deserialize))]
|
|
||||||
// # struct S { /* ... */ }
|
|
||||||
//
|
|
||||||
// The re-exported derives allow crates to use "serde" as the name of their
|
|
||||||
// Serde feature which is more intuitive.
|
|
||||||
//
|
|
||||||
// [dependencies]
|
|
||||||
// serde = { version = "1.0", optional = true, features = ["derive"] }
|
|
||||||
//
|
|
||||||
// # Used like this:
|
|
||||||
// # #[cfg(feature = "serde")]
|
|
||||||
// # #[macro_use]
|
|
||||||
// # extern crate serde;
|
|
||||||
// #
|
|
||||||
// # #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
|
||||||
// # struct S { /* ... */ }
|
|
||||||
//
|
|
||||||
// The reason re-exporting is not enabled by default is that disabling it would
|
// The reason re-exporting is not enabled by default is that disabling it would
|
||||||
// be annoying for crates that provide handwritten impls or data formats. They
|
// be annoying for crates that provide handwritten impls or data formats. They
|
||||||
// would need to disable default features and then explicitly re-enable std.
|
// would need to disable default features and then explicitly re-enable std.
|
||||||
|
|||||||
+6
-18
@@ -11,10 +11,8 @@
|
|||||||
/// input. This requires repetitive implementations of all the [`Deserializer`]
|
/// input. This requires repetitive implementations of all the [`Deserializer`]
|
||||||
/// trait methods.
|
/// trait methods.
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```edition2018
|
||||||
/// # #[macro_use]
|
/// # use serde::forward_to_deserialize_any;
|
||||||
/// # extern crate serde;
|
|
||||||
/// #
|
|
||||||
/// # use serde::de::{value, Deserializer, Visitor};
|
/// # use serde::de::{value, Deserializer, Visitor};
|
||||||
/// #
|
/// #
|
||||||
/// # struct MyDeserializer;
|
/// # struct MyDeserializer;
|
||||||
@@ -43,18 +41,14 @@
|
|||||||
/// # tuple_struct map struct enum identifier ignored_any
|
/// # tuple_struct map struct enum identifier ignored_any
|
||||||
/// # }
|
/// # }
|
||||||
/// # }
|
/// # }
|
||||||
/// #
|
|
||||||
/// # fn main() {}
|
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// The `forward_to_deserialize_any!` macro implements these simple forwarding
|
/// The `forward_to_deserialize_any!` macro implements these simple forwarding
|
||||||
/// methods so that they forward directly to [`Deserializer::deserialize_any`].
|
/// methods so that they forward directly to [`Deserializer::deserialize_any`].
|
||||||
/// You can choose which methods to forward.
|
/// You can choose which methods to forward.
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```edition2018
|
||||||
/// # #[macro_use]
|
/// # use serde::forward_to_deserialize_any;
|
||||||
/// # extern crate serde;
|
|
||||||
/// #
|
|
||||||
/// # use serde::de::{value, Deserializer, Visitor};
|
/// # use serde::de::{value, Deserializer, Visitor};
|
||||||
/// #
|
/// #
|
||||||
/// # struct MyDeserializer;
|
/// # struct MyDeserializer;
|
||||||
@@ -77,8 +71,6 @@
|
|||||||
/// tuple_struct map struct enum identifier ignored_any
|
/// tuple_struct map struct enum identifier ignored_any
|
||||||
/// }
|
/// }
|
||||||
/// }
|
/// }
|
||||||
/// #
|
|
||||||
/// # fn main() {}
|
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// The macro assumes the convention that your `Deserializer` lifetime parameter
|
/// The macro assumes the convention that your `Deserializer` lifetime parameter
|
||||||
@@ -86,12 +78,10 @@
|
|||||||
/// called `V`. A different type parameter and a different lifetime can be
|
/// called `V`. A different type parameter and a different lifetime can be
|
||||||
/// specified explicitly if necessary.
|
/// specified explicitly if necessary.
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```edition2018
|
||||||
/// # #[macro_use]
|
|
||||||
/// # extern crate serde;
|
|
||||||
/// #
|
|
||||||
/// # use std::marker::PhantomData;
|
/// # use std::marker::PhantomData;
|
||||||
/// #
|
/// #
|
||||||
|
/// # use serde::forward_to_deserialize_any;
|
||||||
/// # use serde::de::{value, Deserializer, Visitor};
|
/// # use serde::de::{value, Deserializer, Visitor};
|
||||||
/// #
|
/// #
|
||||||
/// # struct MyDeserializer<V>(PhantomData<V>);
|
/// # struct MyDeserializer<V>(PhantomData<V>);
|
||||||
@@ -113,8 +103,6 @@
|
|||||||
/// tuple_struct map struct enum identifier ignored_any
|
/// tuple_struct map struct enum identifier ignored_any
|
||||||
/// }
|
/// }
|
||||||
/// # }
|
/// # }
|
||||||
/// #
|
|
||||||
/// # fn main() {}
|
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// [`Deserializer`]: trait.Deserializer.html
|
/// [`Deserializer`]: trait.Deserializer.html
|
||||||
|
|||||||
@@ -15,10 +15,7 @@ use ser::{
|
|||||||
/// [`SerializeTuple`], [`SerializeTupleStruct`], [`SerializeTupleVariant`],
|
/// [`SerializeTuple`], [`SerializeTupleStruct`], [`SerializeTupleVariant`],
|
||||||
/// [`SerializeMap`], [`SerializeStruct`], and [`SerializeStructVariant`].
|
/// [`SerializeMap`], [`SerializeStruct`], and [`SerializeStructVariant`].
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```edition2018
|
||||||
/// # #[macro_use]
|
|
||||||
/// # extern crate serde;
|
|
||||||
/// #
|
|
||||||
/// # use serde::ser::{Serializer, Impossible};
|
/// # use serde::ser::{Serializer, Impossible};
|
||||||
/// # use serde::private::ser::Error;
|
/// # use serde::private::ser::Error;
|
||||||
/// #
|
/// #
|
||||||
@@ -44,14 +41,12 @@ use ser::{
|
|||||||
/// }
|
/// }
|
||||||
///
|
///
|
||||||
/// /* other Serializer methods */
|
/// /* other Serializer methods */
|
||||||
/// # __serialize_unimplemented! {
|
/// # serde::__serialize_unimplemented! {
|
||||||
/// # bool i8 i16 i32 i64 u8 u16 u32 u64 f32 f64 char str bytes none some
|
/// # bool i8 i16 i32 i64 u8 u16 u32 u64 f32 f64 char str bytes none some
|
||||||
/// # unit unit_struct unit_variant newtype_struct newtype_variant
|
/// # unit unit_struct unit_variant newtype_struct newtype_variant
|
||||||
/// # tuple tuple_struct tuple_variant map struct struct_variant
|
/// # tuple tuple_struct tuple_variant map struct struct_variant
|
||||||
/// # }
|
/// # }
|
||||||
/// }
|
/// }
|
||||||
/// #
|
|
||||||
/// # fn main() {}
|
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// [`Serializer`]: trait.Serializer.html
|
/// [`Serializer`]: trait.Serializer.html
|
||||||
|
|||||||
+65
-154
@@ -137,7 +137,7 @@ macro_rules! declare_error_trait {
|
|||||||
/// For example, a filesystem [`Path`] may refuse to serialize
|
/// For example, a filesystem [`Path`] may refuse to serialize
|
||||||
/// itself if it contains invalid UTF-8 data.
|
/// itself if it contains invalid UTF-8 data.
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```edition2018
|
||||||
/// # struct Path;
|
/// # struct Path;
|
||||||
/// #
|
/// #
|
||||||
/// # impl Path {
|
/// # impl Path {
|
||||||
@@ -210,7 +210,7 @@ pub trait Serialize {
|
|||||||
/// See the [Implementing `Serialize`] section of the manual for more
|
/// See the [Implementing `Serialize`] section of the manual for more
|
||||||
/// information about how to implement this method.
|
/// information about how to implement this method.
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```edition2018
|
||||||
/// use serde::ser::{Serialize, SerializeStruct, Serializer};
|
/// use serde::ser::{Serialize, SerializeStruct, Serializer};
|
||||||
///
|
///
|
||||||
/// struct Person {
|
/// struct Person {
|
||||||
@@ -377,13 +377,10 @@ pub trait Serializer: Sized {
|
|||||||
|
|
||||||
/// Serialize a `bool` value.
|
/// Serialize a `bool` value.
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```edition2018
|
||||||
/// # #[macro_use]
|
|
||||||
/// # extern crate serde;
|
|
||||||
/// #
|
|
||||||
/// # use serde::Serializer;
|
/// # use serde::Serializer;
|
||||||
/// #
|
/// #
|
||||||
/// # __private_serialize!();
|
/// # serde::__private_serialize!();
|
||||||
/// #
|
/// #
|
||||||
/// impl Serialize for bool {
|
/// impl Serialize for bool {
|
||||||
/// fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
/// fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||||
@@ -393,8 +390,6 @@ pub trait Serializer: Sized {
|
|||||||
/// serializer.serialize_bool(*self)
|
/// serializer.serialize_bool(*self)
|
||||||
/// }
|
/// }
|
||||||
/// }
|
/// }
|
||||||
/// #
|
|
||||||
/// # fn main() {}
|
|
||||||
/// ```
|
/// ```
|
||||||
fn serialize_bool(self, v: bool) -> Result<Self::Ok, Self::Error>;
|
fn serialize_bool(self, v: bool) -> Result<Self::Ok, Self::Error>;
|
||||||
|
|
||||||
@@ -404,13 +399,10 @@ pub trait Serializer: Sized {
|
|||||||
/// reasonable implementation would be to cast the value to `i64` and
|
/// reasonable implementation would be to cast the value to `i64` and
|
||||||
/// forward to `serialize_i64`.
|
/// forward to `serialize_i64`.
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```edition2018
|
||||||
/// # #[macro_use]
|
|
||||||
/// # extern crate serde;
|
|
||||||
/// #
|
|
||||||
/// # use serde::Serializer;
|
/// # use serde::Serializer;
|
||||||
/// #
|
/// #
|
||||||
/// # __private_serialize!();
|
/// # serde::__private_serialize!();
|
||||||
/// #
|
/// #
|
||||||
/// impl Serialize for i8 {
|
/// impl Serialize for i8 {
|
||||||
/// fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
/// fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||||
@@ -420,8 +412,6 @@ pub trait Serializer: Sized {
|
|||||||
/// serializer.serialize_i8(*self)
|
/// serializer.serialize_i8(*self)
|
||||||
/// }
|
/// }
|
||||||
/// }
|
/// }
|
||||||
/// #
|
|
||||||
/// # fn main() {}
|
|
||||||
/// ```
|
/// ```
|
||||||
fn serialize_i8(self, v: i8) -> Result<Self::Ok, Self::Error>;
|
fn serialize_i8(self, v: i8) -> Result<Self::Ok, Self::Error>;
|
||||||
|
|
||||||
@@ -431,13 +421,10 @@ pub trait Serializer: Sized {
|
|||||||
/// reasonable implementation would be to cast the value to `i64` and
|
/// reasonable implementation would be to cast the value to `i64` and
|
||||||
/// forward to `serialize_i64`.
|
/// forward to `serialize_i64`.
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```edition2018
|
||||||
/// # #[macro_use]
|
|
||||||
/// # extern crate serde;
|
|
||||||
/// #
|
|
||||||
/// # use serde::Serializer;
|
/// # use serde::Serializer;
|
||||||
/// #
|
/// #
|
||||||
/// # __private_serialize!();
|
/// # serde::__private_serialize!();
|
||||||
/// #
|
/// #
|
||||||
/// impl Serialize for i16 {
|
/// impl Serialize for i16 {
|
||||||
/// fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
/// fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||||
@@ -447,8 +434,6 @@ pub trait Serializer: Sized {
|
|||||||
/// serializer.serialize_i16(*self)
|
/// serializer.serialize_i16(*self)
|
||||||
/// }
|
/// }
|
||||||
/// }
|
/// }
|
||||||
/// #
|
|
||||||
/// # fn main() {}
|
|
||||||
/// ```
|
/// ```
|
||||||
fn serialize_i16(self, v: i16) -> Result<Self::Ok, Self::Error>;
|
fn serialize_i16(self, v: i16) -> Result<Self::Ok, Self::Error>;
|
||||||
|
|
||||||
@@ -458,13 +443,10 @@ pub trait Serializer: Sized {
|
|||||||
/// reasonable implementation would be to cast the value to `i64` and
|
/// reasonable implementation would be to cast the value to `i64` and
|
||||||
/// forward to `serialize_i64`.
|
/// forward to `serialize_i64`.
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```edition2018
|
||||||
/// # #[macro_use]
|
|
||||||
/// # extern crate serde;
|
|
||||||
/// #
|
|
||||||
/// # use serde::Serializer;
|
/// # use serde::Serializer;
|
||||||
/// #
|
/// #
|
||||||
/// # __private_serialize!();
|
/// # serde::__private_serialize!();
|
||||||
/// #
|
/// #
|
||||||
/// impl Serialize for i32 {
|
/// impl Serialize for i32 {
|
||||||
/// fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
/// fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||||
@@ -474,20 +456,15 @@ pub trait Serializer: Sized {
|
|||||||
/// serializer.serialize_i32(*self)
|
/// serializer.serialize_i32(*self)
|
||||||
/// }
|
/// }
|
||||||
/// }
|
/// }
|
||||||
/// #
|
|
||||||
/// # fn main() {}
|
|
||||||
/// ```
|
/// ```
|
||||||
fn serialize_i32(self, v: i32) -> Result<Self::Ok, Self::Error>;
|
fn serialize_i32(self, v: i32) -> Result<Self::Ok, Self::Error>;
|
||||||
|
|
||||||
/// Serialize an `i64` value.
|
/// Serialize an `i64` value.
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```edition2018
|
||||||
/// # #[macro_use]
|
|
||||||
/// # extern crate serde;
|
|
||||||
/// #
|
|
||||||
/// # use serde::Serializer;
|
/// # use serde::Serializer;
|
||||||
/// #
|
/// #
|
||||||
/// # __private_serialize!();
|
/// # serde::__private_serialize!();
|
||||||
/// #
|
/// #
|
||||||
/// impl Serialize for i64 {
|
/// impl Serialize for i64 {
|
||||||
/// fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
/// fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||||
@@ -497,21 +474,16 @@ pub trait Serializer: Sized {
|
|||||||
/// serializer.serialize_i64(*self)
|
/// serializer.serialize_i64(*self)
|
||||||
/// }
|
/// }
|
||||||
/// }
|
/// }
|
||||||
/// #
|
|
||||||
/// # fn main() {}
|
|
||||||
/// ```
|
/// ```
|
||||||
fn serialize_i64(self, v: i64) -> Result<Self::Ok, Self::Error>;
|
fn serialize_i64(self, v: i64) -> Result<Self::Ok, Self::Error>;
|
||||||
|
|
||||||
serde_if_integer128! {
|
serde_if_integer128! {
|
||||||
/// Serialize an `i128` value.
|
/// Serialize an `i128` value.
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```edition2018
|
||||||
/// # #[macro_use]
|
|
||||||
/// # extern crate serde;
|
|
||||||
/// #
|
|
||||||
/// # use serde::Serializer;
|
/// # use serde::Serializer;
|
||||||
/// #
|
/// #
|
||||||
/// # __private_serialize!();
|
/// # serde::__private_serialize!();
|
||||||
/// #
|
/// #
|
||||||
/// impl Serialize for i128 {
|
/// impl Serialize for i128 {
|
||||||
/// fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
/// fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||||
@@ -521,8 +493,6 @@ pub trait Serializer: Sized {
|
|||||||
/// serializer.serialize_i128(*self)
|
/// serializer.serialize_i128(*self)
|
||||||
/// }
|
/// }
|
||||||
/// }
|
/// }
|
||||||
/// #
|
|
||||||
/// # fn main() {}
|
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// This method is available only on Rust compiler versions >=1.26. The
|
/// This method is available only on Rust compiler versions >=1.26. The
|
||||||
@@ -539,13 +509,10 @@ pub trait Serializer: Sized {
|
|||||||
/// reasonable implementation would be to cast the value to `u64` and
|
/// reasonable implementation would be to cast the value to `u64` and
|
||||||
/// forward to `serialize_u64`.
|
/// forward to `serialize_u64`.
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```edition2018
|
||||||
/// # #[macro_use]
|
|
||||||
/// # extern crate serde;
|
|
||||||
/// #
|
|
||||||
/// # use serde::Serializer;
|
/// # use serde::Serializer;
|
||||||
/// #
|
/// #
|
||||||
/// # __private_serialize!();
|
/// # serde::__private_serialize!();
|
||||||
/// #
|
/// #
|
||||||
/// impl Serialize for u8 {
|
/// impl Serialize for u8 {
|
||||||
/// fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
/// fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||||
@@ -555,8 +522,6 @@ pub trait Serializer: Sized {
|
|||||||
/// serializer.serialize_u8(*self)
|
/// serializer.serialize_u8(*self)
|
||||||
/// }
|
/// }
|
||||||
/// }
|
/// }
|
||||||
/// #
|
|
||||||
/// # fn main() {}
|
|
||||||
/// ```
|
/// ```
|
||||||
fn serialize_u8(self, v: u8) -> Result<Self::Ok, Self::Error>;
|
fn serialize_u8(self, v: u8) -> Result<Self::Ok, Self::Error>;
|
||||||
|
|
||||||
@@ -566,13 +531,10 @@ pub trait Serializer: Sized {
|
|||||||
/// reasonable implementation would be to cast the value to `u64` and
|
/// reasonable implementation would be to cast the value to `u64` and
|
||||||
/// forward to `serialize_u64`.
|
/// forward to `serialize_u64`.
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```edition2018
|
||||||
/// # #[macro_use]
|
|
||||||
/// # extern crate serde;
|
|
||||||
/// #
|
|
||||||
/// # use serde::Serializer;
|
/// # use serde::Serializer;
|
||||||
/// #
|
/// #
|
||||||
/// # __private_serialize!();
|
/// # serde::__private_serialize!();
|
||||||
/// #
|
/// #
|
||||||
/// impl Serialize for u16 {
|
/// impl Serialize for u16 {
|
||||||
/// fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
/// fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||||
@@ -582,8 +544,6 @@ pub trait Serializer: Sized {
|
|||||||
/// serializer.serialize_u16(*self)
|
/// serializer.serialize_u16(*self)
|
||||||
/// }
|
/// }
|
||||||
/// }
|
/// }
|
||||||
/// #
|
|
||||||
/// # fn main() {}
|
|
||||||
/// ```
|
/// ```
|
||||||
fn serialize_u16(self, v: u16) -> Result<Self::Ok, Self::Error>;
|
fn serialize_u16(self, v: u16) -> Result<Self::Ok, Self::Error>;
|
||||||
|
|
||||||
@@ -593,13 +553,10 @@ pub trait Serializer: Sized {
|
|||||||
/// reasonable implementation would be to cast the value to `u64` and
|
/// reasonable implementation would be to cast the value to `u64` and
|
||||||
/// forward to `serialize_u64`.
|
/// forward to `serialize_u64`.
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```edition2018
|
||||||
/// # #[macro_use]
|
|
||||||
/// # extern crate serde;
|
|
||||||
/// #
|
|
||||||
/// # use serde::Serializer;
|
/// # use serde::Serializer;
|
||||||
/// #
|
/// #
|
||||||
/// # __private_serialize!();
|
/// # serde::__private_serialize!();
|
||||||
/// #
|
/// #
|
||||||
/// impl Serialize for u32 {
|
/// impl Serialize for u32 {
|
||||||
/// fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
/// fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||||
@@ -609,20 +566,15 @@ pub trait Serializer: Sized {
|
|||||||
/// serializer.serialize_u32(*self)
|
/// serializer.serialize_u32(*self)
|
||||||
/// }
|
/// }
|
||||||
/// }
|
/// }
|
||||||
/// #
|
|
||||||
/// # fn main() {}
|
|
||||||
/// ```
|
/// ```
|
||||||
fn serialize_u32(self, v: u32) -> Result<Self::Ok, Self::Error>;
|
fn serialize_u32(self, v: u32) -> Result<Self::Ok, Self::Error>;
|
||||||
|
|
||||||
/// Serialize a `u64` value.
|
/// Serialize a `u64` value.
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```edition2018
|
||||||
/// # #[macro_use]
|
|
||||||
/// # extern crate serde;
|
|
||||||
/// #
|
|
||||||
/// # use serde::Serializer;
|
/// # use serde::Serializer;
|
||||||
/// #
|
/// #
|
||||||
/// # __private_serialize!();
|
/// # serde::__private_serialize!();
|
||||||
/// #
|
/// #
|
||||||
/// impl Serialize for u64 {
|
/// impl Serialize for u64 {
|
||||||
/// fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
/// fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||||
@@ -632,21 +584,16 @@ pub trait Serializer: Sized {
|
|||||||
/// serializer.serialize_u64(*self)
|
/// serializer.serialize_u64(*self)
|
||||||
/// }
|
/// }
|
||||||
/// }
|
/// }
|
||||||
/// #
|
|
||||||
/// # fn main() {}
|
|
||||||
/// ```
|
/// ```
|
||||||
fn serialize_u64(self, v: u64) -> Result<Self::Ok, Self::Error>;
|
fn serialize_u64(self, v: u64) -> Result<Self::Ok, Self::Error>;
|
||||||
|
|
||||||
serde_if_integer128! {
|
serde_if_integer128! {
|
||||||
/// Serialize a `u128` value.
|
/// Serialize a `u128` value.
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```edition2018
|
||||||
/// # #[macro_use]
|
|
||||||
/// # extern crate serde;
|
|
||||||
/// #
|
|
||||||
/// # use serde::Serializer;
|
/// # use serde::Serializer;
|
||||||
/// #
|
/// #
|
||||||
/// # __private_serialize!();
|
/// # serde::__private_serialize!();
|
||||||
/// #
|
/// #
|
||||||
/// impl Serialize for u128 {
|
/// impl Serialize for u128 {
|
||||||
/// fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
/// fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||||
@@ -656,8 +603,6 @@ pub trait Serializer: Sized {
|
|||||||
/// serializer.serialize_u128(*self)
|
/// serializer.serialize_u128(*self)
|
||||||
/// }
|
/// }
|
||||||
/// }
|
/// }
|
||||||
/// #
|
|
||||||
/// # fn main() {}
|
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// This method is available only on Rust compiler versions >=1.26. The
|
/// This method is available only on Rust compiler versions >=1.26. The
|
||||||
@@ -674,13 +619,10 @@ pub trait Serializer: Sized {
|
|||||||
/// reasonable implementation would be to cast the value to `f64` and
|
/// reasonable implementation would be to cast the value to `f64` and
|
||||||
/// forward to `serialize_f64`.
|
/// forward to `serialize_f64`.
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```edition2018
|
||||||
/// # #[macro_use]
|
|
||||||
/// # extern crate serde;
|
|
||||||
/// #
|
|
||||||
/// # use serde::Serializer;
|
/// # use serde::Serializer;
|
||||||
/// #
|
/// #
|
||||||
/// # __private_serialize!();
|
/// # serde::__private_serialize!();
|
||||||
/// #
|
/// #
|
||||||
/// impl Serialize for f32 {
|
/// impl Serialize for f32 {
|
||||||
/// fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
/// fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||||
@@ -690,20 +632,15 @@ pub trait Serializer: Sized {
|
|||||||
/// serializer.serialize_f32(*self)
|
/// serializer.serialize_f32(*self)
|
||||||
/// }
|
/// }
|
||||||
/// }
|
/// }
|
||||||
/// #
|
|
||||||
/// # fn main() {}
|
|
||||||
/// ```
|
/// ```
|
||||||
fn serialize_f32(self, v: f32) -> Result<Self::Ok, Self::Error>;
|
fn serialize_f32(self, v: f32) -> Result<Self::Ok, Self::Error>;
|
||||||
|
|
||||||
/// Serialize an `f64` value.
|
/// Serialize an `f64` value.
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```edition2018
|
||||||
/// # #[macro_use]
|
|
||||||
/// # extern crate serde;
|
|
||||||
/// #
|
|
||||||
/// # use serde::Serializer;
|
/// # use serde::Serializer;
|
||||||
/// #
|
/// #
|
||||||
/// # __private_serialize!();
|
/// # serde::__private_serialize!();
|
||||||
/// #
|
/// #
|
||||||
/// impl Serialize for f64 {
|
/// impl Serialize for f64 {
|
||||||
/// fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
/// fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||||
@@ -713,8 +650,6 @@ pub trait Serializer: Sized {
|
|||||||
/// serializer.serialize_f64(*self)
|
/// serializer.serialize_f64(*self)
|
||||||
/// }
|
/// }
|
||||||
/// }
|
/// }
|
||||||
/// #
|
|
||||||
/// # fn main() {}
|
|
||||||
/// ```
|
/// ```
|
||||||
fn serialize_f64(self, v: f64) -> Result<Self::Ok, Self::Error>;
|
fn serialize_f64(self, v: f64) -> Result<Self::Ok, Self::Error>;
|
||||||
|
|
||||||
@@ -723,13 +658,10 @@ pub trait Serializer: Sized {
|
|||||||
/// If the format does not support characters, it is reasonable to serialize
|
/// If the format does not support characters, it is reasonable to serialize
|
||||||
/// it as a single element `str` or a `u32`.
|
/// it as a single element `str` or a `u32`.
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```edition2018
|
||||||
/// # #[macro_use]
|
|
||||||
/// # extern crate serde;
|
|
||||||
/// #
|
|
||||||
/// # use serde::Serializer;
|
/// # use serde::Serializer;
|
||||||
/// #
|
/// #
|
||||||
/// # __private_serialize!();
|
/// # serde::__private_serialize!();
|
||||||
/// #
|
/// #
|
||||||
/// impl Serialize for char {
|
/// impl Serialize for char {
|
||||||
/// fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
/// fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||||
@@ -739,20 +671,15 @@ pub trait Serializer: Sized {
|
|||||||
/// serializer.serialize_char(*self)
|
/// serializer.serialize_char(*self)
|
||||||
/// }
|
/// }
|
||||||
/// }
|
/// }
|
||||||
/// #
|
|
||||||
/// # fn main() {}
|
|
||||||
/// ```
|
/// ```
|
||||||
fn serialize_char(self, v: char) -> Result<Self::Ok, Self::Error>;
|
fn serialize_char(self, v: char) -> Result<Self::Ok, Self::Error>;
|
||||||
|
|
||||||
/// Serialize a `&str`.
|
/// Serialize a `&str`.
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```edition2018
|
||||||
/// # #[macro_use]
|
|
||||||
/// # extern crate serde;
|
|
||||||
/// #
|
|
||||||
/// # use serde::Serializer;
|
/// # use serde::Serializer;
|
||||||
/// #
|
/// #
|
||||||
/// # __private_serialize!();
|
/// # serde::__private_serialize!();
|
||||||
/// #
|
/// #
|
||||||
/// impl Serialize for str {
|
/// impl Serialize for str {
|
||||||
/// fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
/// fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||||
@@ -762,8 +689,6 @@ pub trait Serializer: Sized {
|
|||||||
/// serializer.serialize_str(self)
|
/// serializer.serialize_str(self)
|
||||||
/// }
|
/// }
|
||||||
/// }
|
/// }
|
||||||
/// #
|
|
||||||
/// # fn main() {}
|
|
||||||
/// ```
|
/// ```
|
||||||
fn serialize_str(self, v: &str) -> Result<Self::Ok, Self::Error>;
|
fn serialize_str(self, v: &str) -> Result<Self::Ok, Self::Error>;
|
||||||
|
|
||||||
@@ -775,10 +700,7 @@ pub trait Serializer: Sized {
|
|||||||
/// `serialize_seq`. If forwarded, the implementation looks usually just
|
/// `serialize_seq`. If forwarded, the implementation looks usually just
|
||||||
/// like this:
|
/// like this:
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```edition2018
|
||||||
/// # #[macro_use]
|
|
||||||
/// # extern crate serde;
|
|
||||||
/// #
|
|
||||||
/// # use serde::ser::{Serializer, SerializeSeq};
|
/// # use serde::ser::{Serializer, SerializeSeq};
|
||||||
/// # use serde::private::ser::Error;
|
/// # use serde::private::ser::Error;
|
||||||
/// #
|
/// #
|
||||||
@@ -796,22 +718,18 @@ pub trait Serializer: Sized {
|
|||||||
/// seq.end()
|
/// seq.end()
|
||||||
/// }
|
/// }
|
||||||
/// #
|
/// #
|
||||||
/// # __serialize_unimplemented! {
|
/// # serde::__serialize_unimplemented! {
|
||||||
/// # bool i8 i16 i32 i64 u8 u16 u32 u64 f32 f64 char str none some
|
/// # bool i8 i16 i32 i64 u8 u16 u32 u64 f32 f64 char str none some
|
||||||
/// # unit unit_struct unit_variant newtype_struct newtype_variant
|
/// # unit unit_struct unit_variant newtype_struct newtype_variant
|
||||||
/// # seq tuple tuple_struct tuple_variant map struct struct_variant
|
/// # seq tuple tuple_struct tuple_variant map struct struct_variant
|
||||||
/// # }
|
/// # }
|
||||||
/// # }
|
/// # }
|
||||||
/// #
|
|
||||||
/// # fn main() {}
|
|
||||||
/// ```
|
/// ```
|
||||||
fn serialize_bytes(self, v: &[u8]) -> Result<Self::Ok, Self::Error>;
|
fn serialize_bytes(self, v: &[u8]) -> Result<Self::Ok, Self::Error>;
|
||||||
|
|
||||||
/// Serialize a [`None`] value.
|
/// Serialize a [`None`] value.
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```edition2018
|
||||||
/// # extern crate serde;
|
|
||||||
/// #
|
|
||||||
/// # use serde::{Serialize, Serializer};
|
/// # use serde::{Serialize, Serializer};
|
||||||
/// #
|
/// #
|
||||||
/// # enum Option<T> {
|
/// # enum Option<T> {
|
||||||
@@ -819,7 +737,7 @@ pub trait Serializer: Sized {
|
|||||||
/// # None,
|
/// # None,
|
||||||
/// # }
|
/// # }
|
||||||
/// #
|
/// #
|
||||||
/// # use Option::{Some, None};
|
/// # use self::Option::{Some, None};
|
||||||
/// #
|
/// #
|
||||||
/// impl<T> Serialize for Option<T>
|
/// impl<T> Serialize for Option<T>
|
||||||
/// where
|
/// where
|
||||||
@@ -844,9 +762,7 @@ pub trait Serializer: Sized {
|
|||||||
|
|
||||||
/// Serialize a [`Some(T)`] value.
|
/// Serialize a [`Some(T)`] value.
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```edition2018
|
||||||
/// # extern crate serde;
|
|
||||||
/// #
|
|
||||||
/// # use serde::{Serialize, Serializer};
|
/// # use serde::{Serialize, Serializer};
|
||||||
/// #
|
/// #
|
||||||
/// # enum Option<T> {
|
/// # enum Option<T> {
|
||||||
@@ -854,7 +770,7 @@ pub trait Serializer: Sized {
|
|||||||
/// # None,
|
/// # None,
|
||||||
/// # }
|
/// # }
|
||||||
/// #
|
/// #
|
||||||
/// # use Option::{Some, None};
|
/// # use self::Option::{Some, None};
|
||||||
/// #
|
/// #
|
||||||
/// impl<T> Serialize for Option<T>
|
/// impl<T> Serialize for Option<T>
|
||||||
/// where
|
/// where
|
||||||
@@ -881,13 +797,10 @@ pub trait Serializer: Sized {
|
|||||||
|
|
||||||
/// Serialize a `()` value.
|
/// Serialize a `()` value.
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```edition2018
|
||||||
/// # #[macro_use]
|
|
||||||
/// # extern crate serde;
|
|
||||||
/// #
|
|
||||||
/// # use serde::Serializer;
|
/// # use serde::Serializer;
|
||||||
/// #
|
/// #
|
||||||
/// # __private_serialize!();
|
/// # serde::__private_serialize!();
|
||||||
/// #
|
/// #
|
||||||
/// impl Serialize for () {
|
/// impl Serialize for () {
|
||||||
/// fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
/// fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||||
@@ -897,8 +810,6 @@ pub trait Serializer: Sized {
|
|||||||
/// serializer.serialize_unit()
|
/// serializer.serialize_unit()
|
||||||
/// }
|
/// }
|
||||||
/// }
|
/// }
|
||||||
/// #
|
|
||||||
/// # fn main() {}
|
|
||||||
/// ```
|
/// ```
|
||||||
fn serialize_unit(self) -> Result<Self::Ok, Self::Error>;
|
fn serialize_unit(self) -> Result<Self::Ok, Self::Error>;
|
||||||
|
|
||||||
@@ -906,7 +817,7 @@ pub trait Serializer: Sized {
|
|||||||
///
|
///
|
||||||
/// A reasonable implementation would be to forward to `serialize_unit`.
|
/// A reasonable implementation would be to forward to `serialize_unit`.
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```edition2018
|
||||||
/// use serde::{Serialize, Serializer};
|
/// use serde::{Serialize, Serializer};
|
||||||
///
|
///
|
||||||
/// struct Nothing;
|
/// struct Nothing;
|
||||||
@@ -928,7 +839,7 @@ pub trait Serializer: Sized {
|
|||||||
/// this variant within the enum, and the `variant` is the name of the
|
/// this variant within the enum, and the `variant` is the name of the
|
||||||
/// variant.
|
/// variant.
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```edition2018
|
||||||
/// use serde::{Serialize, Serializer};
|
/// use serde::{Serialize, Serializer};
|
||||||
///
|
///
|
||||||
/// enum E {
|
/// enum E {
|
||||||
@@ -961,7 +872,7 @@ pub trait Serializer: Sized {
|
|||||||
/// wrappers around the data they contain. A reasonable implementation would
|
/// wrappers around the data they contain. A reasonable implementation would
|
||||||
/// be to forward to `value.serialize(self)`.
|
/// be to forward to `value.serialize(self)`.
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```edition2018
|
||||||
/// use serde::{Serialize, Serializer};
|
/// use serde::{Serialize, Serializer};
|
||||||
///
|
///
|
||||||
/// struct Millimeters(u8);
|
/// struct Millimeters(u8);
|
||||||
@@ -989,7 +900,7 @@ pub trait Serializer: Sized {
|
|||||||
/// this variant within the enum, and the `variant` is the name of the
|
/// this variant within the enum, and the `variant` is the name of the
|
||||||
/// variant. The `value` is the data contained within this newtype variant.
|
/// variant. The `value` is the data contained within this newtype variant.
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```edition2018
|
||||||
/// use serde::{Serialize, Serializer};
|
/// use serde::{Serialize, Serializer};
|
||||||
///
|
///
|
||||||
/// enum E {
|
/// enum E {
|
||||||
@@ -1027,7 +938,7 @@ pub trait Serializer: Sized {
|
|||||||
/// not be computable before the sequence is iterated. Some serializers only
|
/// not be computable before the sequence is iterated. Some serializers only
|
||||||
/// support sequences whose length is known up front.
|
/// support sequences whose length is known up front.
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```edition2018
|
||||||
/// # use std::marker::PhantomData;
|
/// # use std::marker::PhantomData;
|
||||||
/// #
|
/// #
|
||||||
/// # struct Vec<T>(PhantomData<T>);
|
/// # struct Vec<T>(PhantomData<T>);
|
||||||
@@ -1072,7 +983,7 @@ pub trait Serializer: Sized {
|
|||||||
/// This call must be followed by zero or more calls to `serialize_element`,
|
/// This call must be followed by zero or more calls to `serialize_element`,
|
||||||
/// then a call to `end`.
|
/// then a call to `end`.
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```edition2018
|
||||||
/// use serde::ser::{Serialize, Serializer, SerializeTuple};
|
/// use serde::ser::{Serialize, Serializer, SerializeTuple};
|
||||||
///
|
///
|
||||||
/// # mod fool {
|
/// # mod fool {
|
||||||
@@ -1102,7 +1013,7 @@ pub trait Serializer: Sized {
|
|||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```edition2018
|
||||||
/// use serde::ser::{Serialize, SerializeTuple, Serializer};
|
/// use serde::ser::{Serialize, SerializeTuple, Serializer};
|
||||||
///
|
///
|
||||||
/// const VRAM_SIZE: usize = 386;
|
/// const VRAM_SIZE: usize = 386;
|
||||||
@@ -1130,7 +1041,7 @@ pub trait Serializer: Sized {
|
|||||||
/// The `name` is the name of the tuple struct and the `len` is the number
|
/// The `name` is the name of the tuple struct and the `len` is the number
|
||||||
/// of data fields that will be serialized.
|
/// of data fields that will be serialized.
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```edition2018
|
||||||
/// use serde::ser::{Serialize, SerializeTupleStruct, Serializer};
|
/// use serde::ser::{Serialize, SerializeTupleStruct, Serializer};
|
||||||
///
|
///
|
||||||
/// struct Rgb(u8, u8, u8);
|
/// struct Rgb(u8, u8, u8);
|
||||||
@@ -1162,7 +1073,7 @@ pub trait Serializer: Sized {
|
|||||||
/// this variant within the enum, the `variant` is the name of the variant,
|
/// this variant within the enum, the `variant` is the name of the variant,
|
||||||
/// and the `len` is the number of data fields that will be serialized.
|
/// and the `len` is the number of data fields that will be serialized.
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```edition2018
|
||||||
/// use serde::ser::{Serialize, SerializeTupleVariant, Serializer};
|
/// use serde::ser::{Serialize, SerializeTupleVariant, Serializer};
|
||||||
///
|
///
|
||||||
/// enum E {
|
/// enum E {
|
||||||
@@ -1208,7 +1119,7 @@ pub trait Serializer: Sized {
|
|||||||
/// be computable before the map is iterated. Some serializers only support
|
/// be computable before the map is iterated. Some serializers only support
|
||||||
/// maps whose length is known up front.
|
/// maps whose length is known up front.
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```edition2018
|
||||||
/// # use std::marker::PhantomData;
|
/// # use std::marker::PhantomData;
|
||||||
/// #
|
/// #
|
||||||
/// # struct HashMap<K, V>(PhantomData<K>, PhantomData<V>);
|
/// # struct HashMap<K, V>(PhantomData<K>, PhantomData<V>);
|
||||||
@@ -1256,7 +1167,7 @@ pub trait Serializer: Sized {
|
|||||||
/// The `name` is the name of the struct and the `len` is the number of
|
/// The `name` is the name of the struct and the `len` is the number of
|
||||||
/// data fields that will be serialized.
|
/// data fields that will be serialized.
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```edition2018
|
||||||
/// use serde::ser::{Serialize, SerializeStruct, Serializer};
|
/// use serde::ser::{Serialize, SerializeStruct, Serializer};
|
||||||
///
|
///
|
||||||
/// struct Rgb {
|
/// struct Rgb {
|
||||||
@@ -1292,7 +1203,7 @@ pub trait Serializer: Sized {
|
|||||||
/// this variant within the enum, the `variant` is the name of the variant,
|
/// this variant within the enum, the `variant` is the name of the variant,
|
||||||
/// and the `len` is the number of data fields that will be serialized.
|
/// and the `len` is the number of data fields that will be serialized.
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```edition2018
|
||||||
/// use serde::ser::{Serialize, SerializeStructVariant, Serializer};
|
/// use serde::ser::{Serialize, SerializeStructVariant, Serializer};
|
||||||
///
|
///
|
||||||
/// enum E {
|
/// enum E {
|
||||||
@@ -1334,7 +1245,7 @@ pub trait Serializer: Sized {
|
|||||||
/// using [`serialize_seq`]. Implementors should not need to override this
|
/// using [`serialize_seq`]. Implementors should not need to override this
|
||||||
/// method.
|
/// method.
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```edition2018
|
||||||
/// use serde::{Serialize, Serializer};
|
/// use serde::{Serialize, Serializer};
|
||||||
///
|
///
|
||||||
/// struct SecretlyOneHigher {
|
/// struct SecretlyOneHigher {
|
||||||
@@ -1371,7 +1282,7 @@ pub trait Serializer: Sized {
|
|||||||
/// using [`serialize_map`]. Implementors should not need to override this
|
/// using [`serialize_map`]. Implementors should not need to override this
|
||||||
/// method.
|
/// method.
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```edition2018
|
||||||
/// use serde::{Serialize, Serializer};
|
/// use serde::{Serialize, Serializer};
|
||||||
/// use std::collections::BTreeSet;
|
/// use std::collections::BTreeSet;
|
||||||
///
|
///
|
||||||
@@ -1411,7 +1322,7 @@ pub trait Serializer: Sized {
|
|||||||
/// delegates to [`serialize_str`]. Serializers are encouraged to provide a
|
/// delegates to [`serialize_str`]. Serializers are encouraged to provide a
|
||||||
/// more efficient implementation if possible.
|
/// more efficient implementation if possible.
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```edition2018
|
||||||
/// # struct DateTime;
|
/// # struct DateTime;
|
||||||
/// #
|
/// #
|
||||||
/// # impl DateTime {
|
/// # impl DateTime {
|
||||||
@@ -1452,7 +1363,7 @@ pub trait Serializer: Sized {
|
|||||||
/// of this method. If no more sensible behavior is possible, the
|
/// of this method. If no more sensible behavior is possible, the
|
||||||
/// implementation is expected to return an error.
|
/// implementation is expected to return an error.
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```edition2018
|
||||||
/// # struct DateTime;
|
/// # struct DateTime;
|
||||||
/// #
|
/// #
|
||||||
/// # impl DateTime {
|
/// # impl DateTime {
|
||||||
@@ -1487,7 +1398,7 @@ pub trait Serializer: Sized {
|
|||||||
/// human-readable one and binary formats like Bincode will prefer the
|
/// human-readable one and binary formats like Bincode will prefer the
|
||||||
/// compact one.
|
/// compact one.
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```edition2018
|
||||||
/// # use std::fmt::{self, Display};
|
/// # use std::fmt::{self, Display};
|
||||||
/// #
|
/// #
|
||||||
/// # struct Timestamp;
|
/// # struct Timestamp;
|
||||||
@@ -1536,7 +1447,7 @@ pub trait Serializer: Sized {
|
|||||||
///
|
///
|
||||||
/// # Example use
|
/// # Example use
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```edition2018
|
||||||
/// # use std::marker::PhantomData;
|
/// # use std::marker::PhantomData;
|
||||||
/// #
|
/// #
|
||||||
/// # struct Vec<T>(PhantomData<T>);
|
/// # struct Vec<T>(PhantomData<T>);
|
||||||
@@ -1600,7 +1511,7 @@ pub trait SerializeSeq {
|
|||||||
///
|
///
|
||||||
/// # Example use
|
/// # Example use
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```edition2018
|
||||||
/// use serde::ser::{Serialize, Serializer, SerializeTuple};
|
/// use serde::ser::{Serialize, Serializer, SerializeTuple};
|
||||||
///
|
///
|
||||||
/// # mod fool {
|
/// # mod fool {
|
||||||
@@ -1630,7 +1541,7 @@ pub trait SerializeSeq {
|
|||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```edition2018
|
||||||
/// # use std::marker::PhantomData;
|
/// # use std::marker::PhantomData;
|
||||||
/// #
|
/// #
|
||||||
/// # struct Array<T>(PhantomData<T>);
|
/// # struct Array<T>(PhantomData<T>);
|
||||||
@@ -1700,7 +1611,7 @@ pub trait SerializeTuple {
|
|||||||
///
|
///
|
||||||
/// # Example use
|
/// # Example use
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```edition2018
|
||||||
/// use serde::ser::{Serialize, SerializeTupleStruct, Serializer};
|
/// use serde::ser::{Serialize, SerializeTupleStruct, Serializer};
|
||||||
///
|
///
|
||||||
/// struct Rgb(u8, u8, u8);
|
/// struct Rgb(u8, u8, u8);
|
||||||
@@ -1745,7 +1656,7 @@ pub trait SerializeTupleStruct {
|
|||||||
///
|
///
|
||||||
/// # Example use
|
/// # Example use
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```edition2018
|
||||||
/// use serde::ser::{Serialize, SerializeTupleVariant, Serializer};
|
/// use serde::ser::{Serialize, SerializeTupleVariant, Serializer};
|
||||||
///
|
///
|
||||||
/// enum E {
|
/// enum E {
|
||||||
@@ -1803,7 +1714,7 @@ pub trait SerializeTupleVariant {
|
|||||||
///
|
///
|
||||||
/// # Example use
|
/// # Example use
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```edition2018
|
||||||
/// # use std::marker::PhantomData;
|
/// # use std::marker::PhantomData;
|
||||||
/// #
|
/// #
|
||||||
/// # struct HashMap<K, V>(PhantomData<K>, PhantomData<V>);
|
/// # struct HashMap<K, V>(PhantomData<K>, PhantomData<V>);
|
||||||
@@ -1914,7 +1825,7 @@ pub trait SerializeMap {
|
|||||||
///
|
///
|
||||||
/// # Example use
|
/// # Example use
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```edition2018
|
||||||
/// use serde::ser::{Serialize, SerializeStruct, Serializer};
|
/// use serde::ser::{Serialize, SerializeStruct, Serializer};
|
||||||
///
|
///
|
||||||
/// struct Rgb {
|
/// struct Rgb {
|
||||||
@@ -1974,7 +1885,7 @@ pub trait SerializeStruct {
|
|||||||
///
|
///
|
||||||
/// # Example use
|
/// # Example use
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```edition2018
|
||||||
/// use serde::ser::{Serialize, SerializeStructVariant, Serializer};
|
/// use serde::ser::{Serialize, SerializeStructVariant, Serializer};
|
||||||
///
|
///
|
||||||
/// enum E {
|
/// enum E {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "serde_derive"
|
name = "serde_derive"
|
||||||
version = "1.0.82" # remember to update html_root_url
|
version = "1.0.85" # 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)]"
|
||||||
|
|||||||
+100
-126
@@ -5,11 +5,11 @@ use syn::spanned::Spanned;
|
|||||||
use syn::{self, Ident, Index, Member};
|
use syn::{self, Ident, Index, Member};
|
||||||
|
|
||||||
use bound;
|
use bound;
|
||||||
|
use dummy;
|
||||||
use fragment::{Expr, Fragment, Match, Stmts};
|
use fragment::{Expr, Fragment, Match, Stmts};
|
||||||
use internals::ast::{Container, Data, Field, Style, Variant};
|
use internals::ast::{Container, Data, Field, Style, Variant};
|
||||||
use internals::{attr, Ctxt, Derive};
|
use internals::{attr, Ctxt, Derive};
|
||||||
use pretend;
|
use pretend;
|
||||||
use try;
|
|
||||||
|
|
||||||
use std::collections::BTreeSet;
|
use std::collections::BTreeSet;
|
||||||
|
|
||||||
@@ -25,11 +25,6 @@ pub fn expand_derive_deserialize(input: &syn::DeriveInput) -> Result<TokenStream
|
|||||||
let ident = &cont.ident;
|
let ident = &cont.ident;
|
||||||
let params = Parameters::new(&cont);
|
let params = Parameters::new(&cont);
|
||||||
let (de_impl_generics, _, ty_generics, where_clause) = split_with_de_lifetime(¶ms);
|
let (de_impl_generics, _, ty_generics, where_clause) = split_with_de_lifetime(¶ms);
|
||||||
let suffix = ident.to_string().trim_left_matches("r#").to_owned();
|
|
||||||
let dummy_const = Ident::new(
|
|
||||||
&format!("_IMPL_DESERIALIZE_FOR_{}", suffix),
|
|
||||||
Span::call_site(),
|
|
||||||
);
|
|
||||||
let body = Stmts(deserialize_body(&cont, ¶ms));
|
let body = Stmts(deserialize_body(&cont, ¶ms));
|
||||||
let delife = params.borrowed.de_lifetime();
|
let delife = params.borrowed.de_lifetime();
|
||||||
|
|
||||||
@@ -65,19 +60,7 @@ pub fn expand_derive_deserialize(input: &syn::DeriveInput) -> Result<TokenStream
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let try_replacement = try::replacement();
|
Ok(dummy::wrap_in_const("DESERIALIZE", ident, impl_block))
|
||||||
let generated = quote! {
|
|
||||||
#[allow(non_upper_case_globals, unused_attributes, unused_qualifications)]
|
|
||||||
const #dummy_const: () = {
|
|
||||||
#[allow(unknown_lints)]
|
|
||||||
#[cfg_attr(feature = "cargo-clippy", allow(useless_attribute))]
|
|
||||||
#[allow(rust_2018_idioms)]
|
|
||||||
extern crate serde as _serde;
|
|
||||||
#try_replacement
|
|
||||||
#impl_block
|
|
||||||
};
|
|
||||||
};
|
|
||||||
Ok(generated)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn precondition(cx: &Ctxt, cont: &Container) {
|
fn precondition(cx: &Ctxt, cont: &Container) {
|
||||||
@@ -1145,18 +1128,52 @@ fn deserialize_enum(
|
|||||||
cattrs: &attr::Container,
|
cattrs: &attr::Container,
|
||||||
) -> Fragment {
|
) -> Fragment {
|
||||||
match *cattrs.tag() {
|
match *cattrs.tag() {
|
||||||
attr::EnumTag::External => deserialize_externally_tagged_enum(params, variants, cattrs),
|
attr::TagType::External => deserialize_externally_tagged_enum(params, variants, cattrs),
|
||||||
attr::EnumTag::Internal { ref tag } => {
|
attr::TagType::Internal { ref tag } => {
|
||||||
deserialize_internally_tagged_enum(params, variants, cattrs, tag)
|
deserialize_internally_tagged_enum(params, variants, cattrs, tag)
|
||||||
}
|
}
|
||||||
attr::EnumTag::Adjacent {
|
attr::TagType::Adjacent {
|
||||||
ref tag,
|
ref tag,
|
||||||
ref content,
|
ref content,
|
||||||
} => deserialize_adjacently_tagged_enum(params, variants, cattrs, tag, content),
|
} => deserialize_adjacently_tagged_enum(params, variants, cattrs, tag, content),
|
||||||
attr::EnumTag::None => deserialize_untagged_enum(params, variants, cattrs),
|
attr::TagType::None => deserialize_untagged_enum(params, variants, cattrs),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn prepare_enum_variant_enum(
|
||||||
|
variants: &[Variant],
|
||||||
|
cattrs: &attr::Container,
|
||||||
|
) -> (TokenStream, Stmts) {
|
||||||
|
let variant_names_idents: Vec<_> = variants
|
||||||
|
.iter()
|
||||||
|
.enumerate()
|
||||||
|
.filter(|&(_, variant)| !variant.attrs.skip_deserializing())
|
||||||
|
.map(|(i, variant)| {
|
||||||
|
(variant.attrs.name().deserialize_name(), field_i(i), variant.attrs.aliases())
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
let other_idx = variants
|
||||||
|
.iter()
|
||||||
|
.position(|ref variant| variant.attrs.other());
|
||||||
|
|
||||||
|
let variants_stmt = {
|
||||||
|
let variant_names = variant_names_idents.iter().map(|&(ref name, _, _)| name);
|
||||||
|
quote! {
|
||||||
|
const VARIANTS: &'static [&'static str] = &[ #(#variant_names),* ];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
let variant_visitor = Stmts(deserialize_generated_identifier(
|
||||||
|
&variant_names_idents,
|
||||||
|
cattrs,
|
||||||
|
true,
|
||||||
|
other_idx,
|
||||||
|
));
|
||||||
|
|
||||||
|
(variants_stmt, variant_visitor)
|
||||||
|
}
|
||||||
|
|
||||||
fn deserialize_externally_tagged_enum(
|
fn deserialize_externally_tagged_enum(
|
||||||
params: &Parameters,
|
params: &Parameters,
|
||||||
variants: &[Variant],
|
variants: &[Variant],
|
||||||
@@ -1168,33 +1185,9 @@ fn deserialize_externally_tagged_enum(
|
|||||||
let delife = params.borrowed.de_lifetime();
|
let delife = params.borrowed.de_lifetime();
|
||||||
|
|
||||||
let type_name = cattrs.name().deserialize_name();
|
let type_name = cattrs.name().deserialize_name();
|
||||||
|
|
||||||
let expecting = format!("enum {}", params.type_name());
|
let expecting = format!("enum {}", params.type_name());
|
||||||
|
|
||||||
let variant_names_idents: Vec<_> = variants
|
let (variants_stmt, variant_visitor) = prepare_enum_variant_enum(variants, cattrs);
|
||||||
.iter()
|
|
||||||
.enumerate()
|
|
||||||
.filter(|&(_, variant)| !variant.attrs.skip_deserializing())
|
|
||||||
.map(|(i, variant)| (variant.attrs.name().deserialize_name(), field_i(i)))
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
let other_idx = variants
|
|
||||||
.iter()
|
|
||||||
.position(|ref variant| variant.attrs.other());
|
|
||||||
|
|
||||||
let variants_stmt = {
|
|
||||||
let variant_names = variant_names_idents.iter().map(|&(ref name, _)| name);
|
|
||||||
quote! {
|
|
||||||
const VARIANTS: &'static [&'static str] = &[ #(#variant_names),* ];
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
let variant_visitor = Stmts(deserialize_generated_identifier(
|
|
||||||
&variant_names_idents,
|
|
||||||
cattrs,
|
|
||||||
true,
|
|
||||||
other_idx,
|
|
||||||
));
|
|
||||||
|
|
||||||
// Match arms to extract a variant from a string
|
// Match arms to extract a variant from a string
|
||||||
let variant_arms = variants
|
let variant_arms = variants
|
||||||
@@ -1260,11 +1253,15 @@ fn deserialize_externally_tagged_enum(
|
|||||||
|
|
||||||
#variants_stmt
|
#variants_stmt
|
||||||
|
|
||||||
_serde::Deserializer::deserialize_enum(__deserializer, #type_name, VARIANTS,
|
_serde::Deserializer::deserialize_enum(
|
||||||
__Visitor {
|
__deserializer,
|
||||||
marker: _serde::export::PhantomData::<#this #ty_generics>,
|
#type_name,
|
||||||
lifetime: _serde::export::PhantomData,
|
VARIANTS,
|
||||||
})
|
__Visitor {
|
||||||
|
marker: _serde::export::PhantomData::<#this #ty_generics>,
|
||||||
|
lifetime: _serde::export::PhantomData,
|
||||||
|
},
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1274,30 +1271,7 @@ fn deserialize_internally_tagged_enum(
|
|||||||
cattrs: &attr::Container,
|
cattrs: &attr::Container,
|
||||||
tag: &str,
|
tag: &str,
|
||||||
) -> Fragment {
|
) -> Fragment {
|
||||||
let variant_names_idents: Vec<_> = variants
|
let (variants_stmt, variant_visitor) = prepare_enum_variant_enum(variants, cattrs);
|
||||||
.iter()
|
|
||||||
.enumerate()
|
|
||||||
.filter(|&(_, variant)| !variant.attrs.skip_deserializing())
|
|
||||||
.map(|(i, variant)| (variant.attrs.name().deserialize_name(), field_i(i)))
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
let other_idx = variants
|
|
||||||
.iter()
|
|
||||||
.position(|ref variant| variant.attrs.other());
|
|
||||||
|
|
||||||
let variants_stmt = {
|
|
||||||
let variant_names = variant_names_idents.iter().map(|&(ref name, _)| name);
|
|
||||||
quote! {
|
|
||||||
const VARIANTS: &'static [&'static str] = &[ #(#variant_names),* ];
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
let variant_visitor = Stmts(deserialize_generated_identifier(
|
|
||||||
&variant_names_idents,
|
|
||||||
cattrs,
|
|
||||||
true,
|
|
||||||
other_idx,
|
|
||||||
));
|
|
||||||
|
|
||||||
// Match arms to extract a variant from a string
|
// Match arms to extract a variant from a string
|
||||||
let variant_arms = variants
|
let variant_arms = variants
|
||||||
@@ -1348,30 +1322,7 @@ fn deserialize_adjacently_tagged_enum(
|
|||||||
split_with_de_lifetime(params);
|
split_with_de_lifetime(params);
|
||||||
let delife = params.borrowed.de_lifetime();
|
let delife = params.borrowed.de_lifetime();
|
||||||
|
|
||||||
let variant_names_idents: Vec<_> = variants
|
let (variants_stmt, variant_visitor) = prepare_enum_variant_enum(variants, cattrs);
|
||||||
.iter()
|
|
||||||
.enumerate()
|
|
||||||
.filter(|&(_, variant)| !variant.attrs.skip_deserializing())
|
|
||||||
.map(|(i, variant)| (variant.attrs.name().deserialize_name(), field_i(i)))
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
let other_idx = variants
|
|
||||||
.iter()
|
|
||||||
.position(|ref variant| variant.attrs.other());
|
|
||||||
|
|
||||||
let variants_stmt = {
|
|
||||||
let variant_names = variant_names_idents.iter().map(|&(ref name, _)| name);
|
|
||||||
quote! {
|
|
||||||
const VARIANTS: &'static [&'static str] = &[ #(#variant_names),* ];
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
let variant_visitor = Stmts(deserialize_generated_identifier(
|
|
||||||
&variant_names_idents,
|
|
||||||
cattrs,
|
|
||||||
true,
|
|
||||||
other_idx,
|
|
||||||
));
|
|
||||||
|
|
||||||
let variant_arms: &Vec<_> = &variants
|
let variant_arms: &Vec<_> = &variants
|
||||||
.iter()
|
.iter()
|
||||||
@@ -1615,12 +1566,14 @@ fn deserialize_adjacently_tagged_enum(
|
|||||||
match try!(_serde::de::SeqAccess::next_element(&mut __seq)) {
|
match try!(_serde::de::SeqAccess::next_element(&mut __seq)) {
|
||||||
_serde::export::Some(__field) => {
|
_serde::export::Some(__field) => {
|
||||||
// Visit the second element - the content.
|
// Visit the second element - the content.
|
||||||
match try!(_serde::de::SeqAccess::next_element_seed(&mut __seq,
|
match try!(_serde::de::SeqAccess::next_element_seed(
|
||||||
__Seed {
|
&mut __seq,
|
||||||
field: __field,
|
__Seed {
|
||||||
marker: _serde::export::PhantomData,
|
field: __field,
|
||||||
lifetime: _serde::export::PhantomData,
|
marker: _serde::export::PhantomData,
|
||||||
})) {
|
lifetime: _serde::export::PhantomData,
|
||||||
|
},
|
||||||
|
)) {
|
||||||
_serde::export::Some(__ret) => _serde::export::Ok(__ret),
|
_serde::export::Some(__ret) => _serde::export::Ok(__ret),
|
||||||
// There is no second element.
|
// There is no second element.
|
||||||
_serde::export::None => {
|
_serde::export::None => {
|
||||||
@@ -1637,11 +1590,15 @@ fn deserialize_adjacently_tagged_enum(
|
|||||||
}
|
}
|
||||||
|
|
||||||
const FIELDS: &'static [&'static str] = &[#tag, #content];
|
const FIELDS: &'static [&'static str] = &[#tag, #content];
|
||||||
_serde::Deserializer::deserialize_struct(__deserializer, #type_name, FIELDS,
|
_serde::Deserializer::deserialize_struct(
|
||||||
|
__deserializer,
|
||||||
|
#type_name,
|
||||||
|
FIELDS,
|
||||||
__Visitor {
|
__Visitor {
|
||||||
marker: _serde::export::PhantomData::<#this #ty_generics>,
|
marker: _serde::export::PhantomData::<#this #ty_generics>,
|
||||||
lifetime: _serde::export::PhantomData,
|
lifetime: _serde::export::PhantomData,
|
||||||
})
|
},
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1877,13 +1834,13 @@ fn deserialize_untagged_newtype_variant(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn deserialize_generated_identifier(
|
fn deserialize_generated_identifier(
|
||||||
fields: &[(String, Ident)],
|
fields: &[(String, Ident, Vec<String>)],
|
||||||
cattrs: &attr::Container,
|
cattrs: &attr::Container,
|
||||||
is_variant: bool,
|
is_variant: bool,
|
||||||
other_idx: Option<usize>,
|
other_idx: Option<usize>,
|
||||||
) -> Fragment {
|
) -> Fragment {
|
||||||
let this = quote!(__Field);
|
let this = quote!(__Field);
|
||||||
let field_idents: &Vec<_> = &fields.iter().map(|&(_, ref ident)| ident).collect();
|
let field_idents: &Vec<_> = &fields.iter().map(|&(_, ref ident, _)| ident).collect();
|
||||||
|
|
||||||
let (ignore_variant, fallthrough) = if !is_variant && cattrs.has_flatten() {
|
let (ignore_variant, fallthrough) = if !is_variant && cattrs.has_flatten() {
|
||||||
let ignore_variant = quote!(__other(_serde::private::de::Content<'de>),);
|
let ignore_variant = quote!(__other(_serde::private::de::Content<'de>),);
|
||||||
@@ -1984,11 +1941,12 @@ fn deserialize_custom_identifier(
|
|||||||
(
|
(
|
||||||
variant.attrs.name().deserialize_name(),
|
variant.attrs.name().deserialize_name(),
|
||||||
variant.ident.clone(),
|
variant.ident.clone(),
|
||||||
|
variant.attrs.aliases(),
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let names = names_idents.iter().map(|&(ref name, _)| name);
|
let names = names_idents.iter().map(|&(ref name, _, _)| name);
|
||||||
|
|
||||||
let names_const = if fallthrough.is_some() {
|
let names_const = if fallthrough.is_some() {
|
||||||
None
|
None
|
||||||
@@ -2039,24 +1997,33 @@ fn deserialize_custom_identifier(
|
|||||||
|
|
||||||
fn deserialize_identifier(
|
fn deserialize_identifier(
|
||||||
this: &TokenStream,
|
this: &TokenStream,
|
||||||
fields: &[(String, Ident)],
|
fields: &[(String, Ident, Vec<String>)],
|
||||||
is_variant: bool,
|
is_variant: bool,
|
||||||
fallthrough: Option<TokenStream>,
|
fallthrough: Option<TokenStream>,
|
||||||
collect_other_fields: bool,
|
collect_other_fields: bool,
|
||||||
) -> Fragment {
|
) -> Fragment {
|
||||||
let field_strs = fields.iter().map(|&(ref name, _)| name);
|
let mut flat_fields = Vec::new();
|
||||||
let field_borrowed_strs = fields.iter().map(|&(ref name, _)| name);
|
for &(_, ref ident, ref aliases) in fields {
|
||||||
let field_bytes = fields
|
flat_fields.extend(aliases.iter().map(|alias| (alias, ident)))
|
||||||
|
}
|
||||||
|
|
||||||
|
let field_strs = flat_fields.iter().map(|&(ref name, _)| name);
|
||||||
|
let field_borrowed_strs = flat_fields.iter().map(|&(ref name, _)| name);
|
||||||
|
let field_bytes = flat_fields
|
||||||
.iter()
|
.iter()
|
||||||
.map(|&(ref name, _)| Literal::byte_string(name.as_bytes()));
|
.map(|&(ref name, _)| Literal::byte_string(name.as_bytes()));
|
||||||
let field_borrowed_bytes = fields
|
let field_borrowed_bytes = flat_fields
|
||||||
.iter()
|
.iter()
|
||||||
.map(|&(ref name, _)| Literal::byte_string(name.as_bytes()));
|
.map(|&(ref name, _)| Literal::byte_string(name.as_bytes()));
|
||||||
|
|
||||||
let constructors: &Vec<_> = &fields
|
let constructors: &Vec<_> = &flat_fields
|
||||||
.iter()
|
.iter()
|
||||||
.map(|&(_, ref ident)| quote!(#this::#ident))
|
.map(|&(_, ref ident)| quote!(#this::#ident))
|
||||||
.collect();
|
.collect();
|
||||||
|
let main_constructors: &Vec<_> = &fields
|
||||||
|
.iter()
|
||||||
|
.map(|&(_, ref ident, _)| quote!(#this::#ident))
|
||||||
|
.collect();
|
||||||
|
|
||||||
let expecting = if is_variant {
|
let expecting = if is_variant {
|
||||||
"variant identifier"
|
"variant identifier"
|
||||||
@@ -2244,11 +2211,12 @@ fn deserialize_identifier(
|
|||||||
{
|
{
|
||||||
match __value {
|
match __value {
|
||||||
#(
|
#(
|
||||||
#variant_indices => _serde::export::Ok(#constructors),
|
#variant_indices => _serde::export::Ok(#main_constructors),
|
||||||
)*
|
)*
|
||||||
_ => _serde::export::Err(_serde::de::Error::invalid_value(
|
_ => _serde::export::Err(_serde::de::Error::invalid_value(
|
||||||
_serde::de::Unexpected::Unsigned(__value),
|
_serde::de::Unexpected::Unsigned(__value),
|
||||||
&#fallthrough_msg))
|
&#fallthrough_msg,
|
||||||
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2306,11 +2274,13 @@ fn deserialize_struct_as_struct_visitor(
|
|||||||
.iter()
|
.iter()
|
||||||
.enumerate()
|
.enumerate()
|
||||||
.filter(|&(_, field)| !field.attrs.skip_deserializing())
|
.filter(|&(_, field)| !field.attrs.skip_deserializing())
|
||||||
.map(|(i, field)| (field.attrs.name().deserialize_name(), field_i(i)))
|
.map(|(i, field)| {
|
||||||
|
(field.attrs.name().deserialize_name(), field_i(i), field.attrs.aliases())
|
||||||
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let fields_stmt = {
|
let fields_stmt = {
|
||||||
let field_names = field_names_idents.iter().map(|&(ref name, _)| name);
|
let field_names = field_names_idents.iter().map(|&(ref name, _, _)| name);
|
||||||
quote_block! {
|
quote_block! {
|
||||||
const FIELDS: &'static [&'static str] = &[ #(#field_names),* ];
|
const FIELDS: &'static [&'static str] = &[ #(#field_names),* ];
|
||||||
}
|
}
|
||||||
@@ -2333,7 +2303,9 @@ fn deserialize_struct_as_map_visitor(
|
|||||||
.iter()
|
.iter()
|
||||||
.enumerate()
|
.enumerate()
|
||||||
.filter(|&(_, field)| !field.attrs.skip_deserializing() && !field.attrs.flatten())
|
.filter(|&(_, field)| !field.attrs.skip_deserializing() && !field.attrs.flatten())
|
||||||
.map(|(i, field)| (field.attrs.name().deserialize_name(), field_i(i)))
|
.map(|(i, field)| {
|
||||||
|
(field.attrs.name().deserialize_name(), field_i(i), field.attrs.aliases())
|
||||||
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let field_visitor = deserialize_generated_identifier(&field_names_idents, cattrs, false, None);
|
let field_visitor = deserialize_generated_identifier(&field_names_idents, cattrs, false, None);
|
||||||
@@ -2564,11 +2536,13 @@ fn deserialize_struct_as_struct_in_place_visitor(
|
|||||||
.iter()
|
.iter()
|
||||||
.enumerate()
|
.enumerate()
|
||||||
.filter(|&(_, field)| !field.attrs.skip_deserializing())
|
.filter(|&(_, field)| !field.attrs.skip_deserializing())
|
||||||
.map(|(i, field)| (field.attrs.name().deserialize_name(), field_i(i)))
|
.map(|(i, field)| {
|
||||||
|
(field.attrs.name().deserialize_name(), field_i(i), field.attrs.aliases())
|
||||||
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let fields_stmt = {
|
let fields_stmt = {
|
||||||
let field_names = field_names_idents.iter().map(|&(ref name, _)| name);
|
let field_names = field_names_idents.iter().map(|&(ref name, _, _)| name);
|
||||||
quote_block! {
|
quote_block! {
|
||||||
const FIELDS: &'static [&'static str] = &[ #(#field_names),* ];
|
const FIELDS: &'static [&'static str] = &[ #(#field_names),* ];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,32 @@
|
|||||||
|
use proc_macro2::{Ident, Span, TokenStream};
|
||||||
|
|
||||||
|
use try;
|
||||||
|
|
||||||
|
pub fn wrap_in_const(trait_: &str, ty: &Ident, code: TokenStream) -> TokenStream {
|
||||||
|
let try_replacement = try::replacement();
|
||||||
|
|
||||||
|
let dummy_const = Ident::new(
|
||||||
|
&format!("_IMPL_{}_FOR_{}", trait_, unraw(ty)),
|
||||||
|
Span::call_site(),
|
||||||
|
);
|
||||||
|
|
||||||
|
quote! {
|
||||||
|
#[allow(non_upper_case_globals, unused_attributes, unused_qualifications)]
|
||||||
|
const #dummy_const: () = {
|
||||||
|
#[allow(unknown_lints)]
|
||||||
|
#[cfg_attr(feature = "cargo-clippy", allow(useless_attribute))]
|
||||||
|
#[allow(rust_2018_idioms)]
|
||||||
|
extern crate serde as _serde;
|
||||||
|
#try_replacement
|
||||||
|
#code
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[allow(deprecated)]
|
||||||
|
fn unraw(ident: &Ident) -> String {
|
||||||
|
// str::trim_start_matches was added in 1.30, trim_left_matches deprecated
|
||||||
|
// in 1.33. We currently support rustc back to 1.15 so we need to continue
|
||||||
|
// to use the deprecated one.
|
||||||
|
ident.to_string().trim_left_matches("r#").to_owned()
|
||||||
|
}
|
||||||
@@ -85,12 +85,14 @@ impl<'a> Container<'a> {
|
|||||||
match data {
|
match data {
|
||||||
Data::Enum(ref mut variants) => {
|
Data::Enum(ref mut variants) => {
|
||||||
for variant in variants {
|
for variant in variants {
|
||||||
variant.attrs.rename_by_rule(attrs.rename_all());
|
variant.attrs.rename_by_rules(attrs.rename_all_rules());
|
||||||
for field in &mut variant.fields {
|
for field in &mut variant.fields {
|
||||||
if field.attrs.flatten() {
|
if field.attrs.flatten() {
|
||||||
has_flatten = true;
|
has_flatten = true;
|
||||||
}
|
}
|
||||||
field.attrs.rename_by_rule(variant.attrs.rename_all());
|
field
|
||||||
|
.attrs
|
||||||
|
.rename_by_rules(variant.attrs.rename_all_rules());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -99,7 +101,7 @@ impl<'a> Container<'a> {
|
|||||||
if field.attrs.flatten() {
|
if field.attrs.flatten() {
|
||||||
has_flatten = true;
|
has_flatten = true;
|
||||||
}
|
}
|
||||||
field.attrs.rename_by_rule(attrs.rename_all());
|
field.attrs.rename_by_rules(attrs.rename_all_rules());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,7 +20,6 @@ use syn::NestedMeta::{Literal, Meta};
|
|||||||
|
|
||||||
pub use internals::case::RenameRule;
|
pub use internals::case::RenameRule;
|
||||||
|
|
||||||
#[derive(Clone)]
|
|
||||||
struct Attr<'c, T> {
|
struct Attr<'c, T> {
|
||||||
cx: &'c Ctxt,
|
cx: &'c Ctxt,
|
||||||
name: &'static str,
|
name: &'static str,
|
||||||
@@ -90,16 +89,93 @@ impl<'c> BoolAttr<'c> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Name {
|
struct VecAttr<'c, T> {
|
||||||
serialize: String,
|
cx: &'c Ctxt,
|
||||||
deserialize: String,
|
name: &'static str,
|
||||||
|
first_dup_tokens: TokenStream,
|
||||||
|
values: Vec<T>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'c, T> VecAttr<'c, T> {
|
||||||
|
fn none(cx: &'c Ctxt, name: &'static str) -> Self {
|
||||||
|
VecAttr {
|
||||||
|
cx: cx,
|
||||||
|
name: name,
|
||||||
|
first_dup_tokens: TokenStream::new(),
|
||||||
|
values: Vec::new(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn insert<A: ToTokens>(&mut self, obj: A, value: T) {
|
||||||
|
if self.values.len() == 1 {
|
||||||
|
self.first_dup_tokens = obj.into_token_stream();
|
||||||
|
}
|
||||||
|
self.values.push(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn at_most_one(mut self) -> Result<Option<T>, ()> {
|
||||||
|
if self.values.len() > 1 {
|
||||||
|
let dup_token = self.first_dup_tokens;
|
||||||
|
self.cx
|
||||||
|
.error_spanned_by(dup_token, format!("duplicate serde attribute `{}`", self.name));
|
||||||
|
Err(())
|
||||||
|
} else {
|
||||||
|
Ok(self.values.pop())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get(self) -> Vec<T> {
|
||||||
|
self.values
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct Name {
|
||||||
|
serialize: String,
|
||||||
|
serialize_renamed: bool,
|
||||||
|
deserialize: String,
|
||||||
|
deserialize_renamed: bool,
|
||||||
|
deserialize_aliases: Vec<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[allow(deprecated)]
|
||||||
fn unraw(ident: &Ident) -> String {
|
fn unraw(ident: &Ident) -> String {
|
||||||
|
// str::trim_start_matches was added in 1.30, trim_left_matches deprecated
|
||||||
|
// in 1.33. We currently support rustc back to 1.15 so we need to continue
|
||||||
|
// to use the deprecated one.
|
||||||
ident.to_string().trim_left_matches("r#").to_owned()
|
ident.to_string().trim_left_matches("r#").to_owned()
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Name {
|
impl Name {
|
||||||
|
fn from_attrs(
|
||||||
|
source_name: String,
|
||||||
|
ser_name: Attr<String>,
|
||||||
|
de_name: Attr<String>,
|
||||||
|
de_aliases: Option<VecAttr<String>>,
|
||||||
|
) -> Name {
|
||||||
|
let deserialize_aliases = match de_aliases {
|
||||||
|
Some(de_aliases) => {
|
||||||
|
let mut alias_list = BTreeSet::new();
|
||||||
|
for alias_name in de_aliases.get() {
|
||||||
|
alias_list.insert(alias_name);
|
||||||
|
}
|
||||||
|
alias_list.into_iter().collect()
|
||||||
|
}
|
||||||
|
None => Vec::new(),
|
||||||
|
};
|
||||||
|
|
||||||
|
let ser_name = ser_name.get();
|
||||||
|
let ser_renamed = ser_name.is_some();
|
||||||
|
let de_name = de_name.get();
|
||||||
|
let de_renamed = de_name.is_some();
|
||||||
|
Name {
|
||||||
|
serialize: ser_name.unwrap_or_else(|| source_name.clone()),
|
||||||
|
serialize_renamed: ser_renamed,
|
||||||
|
deserialize: de_name.unwrap_or(source_name),
|
||||||
|
deserialize_renamed: de_renamed,
|
||||||
|
deserialize_aliases: deserialize_aliases,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Return the container name for the container when serializing.
|
/// Return the container name for the container when serializing.
|
||||||
pub fn serialize_name(&self) -> String {
|
pub fn serialize_name(&self) -> String {
|
||||||
self.serialize.clone()
|
self.serialize.clone()
|
||||||
@@ -109,6 +185,20 @@ impl Name {
|
|||||||
pub fn deserialize_name(&self) -> String {
|
pub fn deserialize_name(&self) -> String {
|
||||||
self.deserialize.clone()
|
self.deserialize.clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn deserialize_aliases(&self) -> Vec<String> {
|
||||||
|
let mut aliases = self.deserialize_aliases.clone();
|
||||||
|
let main_name = self.deserialize_name();
|
||||||
|
if !aliases.contains(&main_name) {
|
||||||
|
aliases.push(main_name);
|
||||||
|
}
|
||||||
|
aliases
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct RenameAllRules {
|
||||||
|
serialize: RenameRule,
|
||||||
|
deserialize: RenameRule,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Represents struct or enum attribute information.
|
/// Represents struct or enum attribute information.
|
||||||
@@ -117,10 +207,10 @@ pub struct Container {
|
|||||||
transparent: bool,
|
transparent: bool,
|
||||||
deny_unknown_fields: bool,
|
deny_unknown_fields: bool,
|
||||||
default: Default,
|
default: Default,
|
||||||
rename_all: RenameRule,
|
rename_all_rules: RenameAllRules,
|
||||||
ser_bound: Option<Vec<syn::WherePredicate>>,
|
ser_bound: Option<Vec<syn::WherePredicate>>,
|
||||||
de_bound: Option<Vec<syn::WherePredicate>>,
|
de_bound: Option<Vec<syn::WherePredicate>>,
|
||||||
tag: EnumTag,
|
tag: TagType,
|
||||||
type_from: Option<syn::Type>,
|
type_from: Option<syn::Type>,
|
||||||
type_into: Option<syn::Type>,
|
type_into: Option<syn::Type>,
|
||||||
remote: Option<syn::Path>,
|
remote: Option<syn::Path>,
|
||||||
@@ -129,7 +219,7 @@ pub struct Container {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Styles of representing an enum.
|
/// Styles of representing an enum.
|
||||||
pub enum EnumTag {
|
pub enum TagType {
|
||||||
/// The default.
|
/// The default.
|
||||||
///
|
///
|
||||||
/// ```json
|
/// ```json
|
||||||
@@ -194,7 +284,8 @@ impl Container {
|
|||||||
let mut transparent = BoolAttr::none(cx, "transparent");
|
let mut transparent = BoolAttr::none(cx, "transparent");
|
||||||
let mut deny_unknown_fields = BoolAttr::none(cx, "deny_unknown_fields");
|
let mut deny_unknown_fields = BoolAttr::none(cx, "deny_unknown_fields");
|
||||||
let mut default = Attr::none(cx, "default");
|
let mut default = Attr::none(cx, "default");
|
||||||
let mut rename_all = Attr::none(cx, "rename_all");
|
let mut rename_all_ser_rule = Attr::none(cx, "rename_all");
|
||||||
|
let mut rename_all_de_rule = Attr::none(cx, "rename_all");
|
||||||
let mut ser_bound = Attr::none(cx, "bound");
|
let mut ser_bound = Attr::none(cx, "bound");
|
||||||
let mut de_bound = Attr::none(cx, "bound");
|
let mut de_bound = Attr::none(cx, "bound");
|
||||||
let mut untagged = BoolAttr::none(cx, "untagged");
|
let mut untagged = BoolAttr::none(cx, "untagged");
|
||||||
@@ -229,7 +320,10 @@ impl Container {
|
|||||||
Meta(NameValue(ref m)) if m.ident == "rename_all" => {
|
Meta(NameValue(ref m)) if m.ident == "rename_all" => {
|
||||||
if let Ok(s) = get_lit_str(cx, &m.ident, &m.ident, &m.lit) {
|
if let Ok(s) = get_lit_str(cx, &m.ident, &m.ident, &m.lit) {
|
||||||
match RenameRule::from_str(&s.value()) {
|
match RenameRule::from_str(&s.value()) {
|
||||||
Ok(rename_rule) => rename_all.set(&m.ident, rename_rule),
|
Ok(rename_rule) => {
|
||||||
|
rename_all_ser_rule.set(&m.ident, rename_rule);
|
||||||
|
rename_all_de_rule.set(&m.ident, rename_rule);
|
||||||
|
}
|
||||||
Err(()) => cx.error_spanned_by(
|
Err(()) => cx.error_spanned_by(
|
||||||
s,
|
s,
|
||||||
format!(
|
format!(
|
||||||
@@ -242,6 +336,42 @@ impl Container {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Parse `#[serde(rename_all(serialize = "foo", deserialize = "bar"))]`
|
||||||
|
Meta(List(ref m)) if m.ident == "rename_all" => {
|
||||||
|
if let Ok((ser, de)) = get_renames(cx, &m.nested) {
|
||||||
|
if let Some(ser) = ser {
|
||||||
|
match RenameRule::from_str(&ser.value()) {
|
||||||
|
Ok(rename_rule) => {
|
||||||
|
rename_all_ser_rule.set(&m.ident, rename_rule)
|
||||||
|
}
|
||||||
|
Err(()) => cx.error_spanned_by(
|
||||||
|
ser,
|
||||||
|
format!(
|
||||||
|
"unknown rename rule for #[serde(rename_all \
|
||||||
|
= {:?})]",
|
||||||
|
ser.value(),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if let Some(de) = de {
|
||||||
|
match RenameRule::from_str(&de.value()) {
|
||||||
|
Ok(rename_rule) => {
|
||||||
|
rename_all_de_rule.set(&m.ident, rename_rule)
|
||||||
|
}
|
||||||
|
Err(()) => cx.error_spanned_by(
|
||||||
|
de,
|
||||||
|
format!(
|
||||||
|
"unknown rename rule for #[serde(rename_all \
|
||||||
|
= {:?})]",
|
||||||
|
de.value(),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Parse `#[serde(transparent)]`
|
// Parse `#[serde(transparent)]`
|
||||||
Meta(Word(ref word)) if word == "transparent" => {
|
Meta(Word(ref word)) if word == "transparent" => {
|
||||||
transparent.set_true(word);
|
transparent.set_true(word);
|
||||||
@@ -361,20 +491,27 @@ impl Container {
|
|||||||
syn::Data::Enum(_) => {
|
syn::Data::Enum(_) => {
|
||||||
internal_tag.set(&m.ident, s.value());
|
internal_tag.set(&m.ident, s.value());
|
||||||
}
|
}
|
||||||
syn::Data::Struct(syn::DataStruct {
|
syn::Data::Struct(syn::DataStruct { ref fields, .. }) => {
|
||||||
ref struct_token, ..
|
match *fields {
|
||||||
}) => {
|
syn::Fields::Named(_) => {
|
||||||
cx.error_spanned_by(
|
internal_tag.set(&m.ident, s.value());
|
||||||
struct_token,
|
}
|
||||||
"#[serde(tag = \"...\")] can only be used on enums",
|
syn::Fields::Unnamed(_) | syn::Fields::Unit => {
|
||||||
);
|
cx.error_spanned_by(
|
||||||
|
fields,
|
||||||
|
"#[serde(tag = \"...\")] can only be used on enums \
|
||||||
|
and structs with named fields",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
syn::Data::Union(syn::DataUnion {
|
syn::Data::Union(syn::DataUnion {
|
||||||
ref union_token, ..
|
ref union_token, ..
|
||||||
}) => {
|
}) => {
|
||||||
cx.error_spanned_by(
|
cx.error_spanned_by(
|
||||||
union_token,
|
union_token,
|
||||||
"#[serde(tag = \"...\")] can only be used on enums",
|
"#[serde(tag = \"...\")] can only be used on enums \
|
||||||
|
and structs with named fields",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -458,14 +595,14 @@ impl Container {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Container {
|
Container {
|
||||||
name: Name {
|
name: Name::from_attrs(unraw(&item.ident), ser_name, de_name, None),
|
||||||
serialize: ser_name.get().unwrap_or_else(|| unraw(&item.ident)),
|
|
||||||
deserialize: de_name.get().unwrap_or_else(|| unraw(&item.ident)),
|
|
||||||
},
|
|
||||||
transparent: transparent.get(),
|
transparent: transparent.get(),
|
||||||
deny_unknown_fields: deny_unknown_fields.get(),
|
deny_unknown_fields: deny_unknown_fields.get(),
|
||||||
default: default.get().unwrap_or(Default::None),
|
default: default.get().unwrap_or(Default::None),
|
||||||
rename_all: rename_all.get().unwrap_or(RenameRule::None),
|
rename_all_rules: RenameAllRules {
|
||||||
|
serialize: rename_all_ser_rule.get().unwrap_or(RenameRule::None),
|
||||||
|
deserialize: rename_all_de_rule.get().unwrap_or(RenameRule::None),
|
||||||
|
},
|
||||||
ser_bound: ser_bound.get(),
|
ser_bound: ser_bound.get(),
|
||||||
de_bound: de_bound.get(),
|
de_bound: de_bound.get(),
|
||||||
tag: decide_tag(cx, item, untagged, internal_tag, content),
|
tag: decide_tag(cx, item, untagged, internal_tag, content),
|
||||||
@@ -481,8 +618,8 @@ impl Container {
|
|||||||
&self.name
|
&self.name
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn rename_all(&self) -> &RenameRule {
|
pub fn rename_all_rules(&self) -> &RenameAllRules {
|
||||||
&self.rename_all
|
&self.rename_all_rules
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn transparent(&self) -> bool {
|
pub fn transparent(&self) -> bool {
|
||||||
@@ -505,7 +642,7 @@ impl Container {
|
|||||||
self.de_bound.as_ref().map(|vec| &vec[..])
|
self.de_bound.as_ref().map(|vec| &vec[..])
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn tag(&self) -> &EnumTag {
|
pub fn tag(&self) -> &TagType {
|
||||||
&self.tag
|
&self.tag
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -540,14 +677,14 @@ fn decide_tag(
|
|||||||
untagged: BoolAttr,
|
untagged: BoolAttr,
|
||||||
internal_tag: Attr<String>,
|
internal_tag: Attr<String>,
|
||||||
content: Attr<String>,
|
content: Attr<String>,
|
||||||
) -> EnumTag {
|
) -> TagType {
|
||||||
match (
|
match (
|
||||||
untagged.0.get_with_tokens(),
|
untagged.0.get_with_tokens(),
|
||||||
internal_tag.get_with_tokens(),
|
internal_tag.get_with_tokens(),
|
||||||
content.get_with_tokens(),
|
content.get_with_tokens(),
|
||||||
) {
|
) {
|
||||||
(None, None, None) => EnumTag::External,
|
(None, None, None) => TagType::External,
|
||||||
(Some(_), None, None) => EnumTag::None,
|
(Some(_), None, None) => TagType::None,
|
||||||
(None, Some((_, tag)), None) => {
|
(None, Some((_, tag)), None) => {
|
||||||
// Check that there are no tuple variants.
|
// Check that there are no tuple variants.
|
||||||
if let syn::Data::Enum(ref data) = item.data {
|
if let syn::Data::Enum(ref data) = item.data {
|
||||||
@@ -567,7 +704,7 @@ fn decide_tag(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
EnumTag::Internal { tag: tag }
|
TagType::Internal { tag: tag }
|
||||||
}
|
}
|
||||||
(Some((untagged_tokens, _)), Some((tag_tokens, _)), None) => {
|
(Some((untagged_tokens, _)), Some((tag_tokens, _)), None) => {
|
||||||
cx.error_spanned_by(
|
cx.error_spanned_by(
|
||||||
@@ -578,14 +715,14 @@ fn decide_tag(
|
|||||||
tag_tokens,
|
tag_tokens,
|
||||||
"enum cannot be both untagged and internally tagged",
|
"enum cannot be both untagged and internally tagged",
|
||||||
);
|
);
|
||||||
EnumTag::External // doesn't matter, will error
|
TagType::External // doesn't matter, will error
|
||||||
}
|
}
|
||||||
(None, None, Some((content_tokens, _))) => {
|
(None, None, Some((content_tokens, _))) => {
|
||||||
cx.error_spanned_by(
|
cx.error_spanned_by(
|
||||||
content_tokens,
|
content_tokens,
|
||||||
"#[serde(tag = \"...\", content = \"...\")] must be used together",
|
"#[serde(tag = \"...\", content = \"...\")] must be used together",
|
||||||
);
|
);
|
||||||
EnumTag::External
|
TagType::External
|
||||||
}
|
}
|
||||||
(Some((untagged_tokens, _)), None, Some((content_tokens, _))) => {
|
(Some((untagged_tokens, _)), None, Some((content_tokens, _))) => {
|
||||||
cx.error_spanned_by(
|
cx.error_spanned_by(
|
||||||
@@ -596,9 +733,9 @@ fn decide_tag(
|
|||||||
content_tokens,
|
content_tokens,
|
||||||
"untagged enum cannot have #[serde(content = \"...\")]",
|
"untagged enum cannot have #[serde(content = \"...\")]",
|
||||||
);
|
);
|
||||||
EnumTag::External
|
TagType::External
|
||||||
}
|
}
|
||||||
(None, Some((_, tag)), Some((_, content))) => EnumTag::Adjacent {
|
(None, Some((_, tag)), Some((_, content))) => TagType::Adjacent {
|
||||||
tag: tag,
|
tag: tag,
|
||||||
content: content,
|
content: content,
|
||||||
},
|
},
|
||||||
@@ -615,7 +752,7 @@ fn decide_tag(
|
|||||||
content_tokens,
|
content_tokens,
|
||||||
"untagged enum cannot have #[serde(tag = \"...\", content = \"...\")]",
|
"untagged enum cannot have #[serde(tag = \"...\", content = \"...\")]",
|
||||||
);
|
);
|
||||||
EnumTag::External
|
TagType::External
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -703,9 +840,7 @@ fn decide_identifier(
|
|||||||
/// Represents variant attribute information
|
/// Represents variant attribute information
|
||||||
pub struct Variant {
|
pub struct Variant {
|
||||||
name: Name,
|
name: Name,
|
||||||
ser_renamed: bool,
|
rename_all_rules: RenameAllRules,
|
||||||
de_renamed: bool,
|
|
||||||
rename_all: RenameRule,
|
|
||||||
ser_bound: Option<Vec<syn::WherePredicate>>,
|
ser_bound: Option<Vec<syn::WherePredicate>>,
|
||||||
de_bound: Option<Vec<syn::WherePredicate>>,
|
de_bound: Option<Vec<syn::WherePredicate>>,
|
||||||
skip_deserializing: bool,
|
skip_deserializing: bool,
|
||||||
@@ -720,9 +855,11 @@ impl Variant {
|
|||||||
pub fn from_ast(cx: &Ctxt, variant: &syn::Variant) -> Self {
|
pub fn from_ast(cx: &Ctxt, variant: &syn::Variant) -> Self {
|
||||||
let mut ser_name = Attr::none(cx, "rename");
|
let mut ser_name = Attr::none(cx, "rename");
|
||||||
let mut de_name = Attr::none(cx, "rename");
|
let mut de_name = Attr::none(cx, "rename");
|
||||||
|
let mut de_aliases = VecAttr::none(cx, "rename");
|
||||||
let mut skip_deserializing = BoolAttr::none(cx, "skip_deserializing");
|
let mut skip_deserializing = BoolAttr::none(cx, "skip_deserializing");
|
||||||
let mut skip_serializing = BoolAttr::none(cx, "skip_serializing");
|
let mut skip_serializing = BoolAttr::none(cx, "skip_serializing");
|
||||||
let mut rename_all = Attr::none(cx, "rename_all");
|
let mut rename_all_ser_rule = Attr::none(cx, "rename_all");
|
||||||
|
let mut rename_all_de_rule = Attr::none(cx, "rename_all");
|
||||||
let mut ser_bound = Attr::none(cx, "bound");
|
let mut ser_bound = Attr::none(cx, "bound");
|
||||||
let mut de_bound = Attr::none(cx, "bound");
|
let mut de_bound = Attr::none(cx, "bound");
|
||||||
let mut other = BoolAttr::none(cx, "other");
|
let mut other = BoolAttr::none(cx, "other");
|
||||||
@@ -737,15 +874,26 @@ impl Variant {
|
|||||||
Meta(NameValue(ref m)) if m.ident == "rename" => {
|
Meta(NameValue(ref m)) if m.ident == "rename" => {
|
||||||
if let Ok(s) = get_lit_str(cx, &m.ident, &m.ident, &m.lit) {
|
if let Ok(s) = get_lit_str(cx, &m.ident, &m.ident, &m.lit) {
|
||||||
ser_name.set(&m.ident, s.value());
|
ser_name.set(&m.ident, s.value());
|
||||||
de_name.set(&m.ident, s.value());
|
de_name.set_if_none(s.value());
|
||||||
|
de_aliases.insert(&m.ident, s.value());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse `#[serde(rename(serialize = "foo", deserialize = "bar"))]`
|
// Parse `#[serde(rename(serialize = "foo", deserialize = "bar"))]`
|
||||||
Meta(List(ref m)) if m.ident == "rename" => {
|
Meta(List(ref m)) if m.ident == "rename" => {
|
||||||
if let Ok((ser, de)) = get_renames(cx, &m.nested) {
|
if let Ok((ser, de)) = get_multiple_renames(cx, &m.nested) {
|
||||||
ser_name.set_opt(&m.ident, ser.map(syn::LitStr::value));
|
ser_name.set_opt(&m.ident, ser.map(syn::LitStr::value));
|
||||||
de_name.set_opt(&m.ident, de.map(syn::LitStr::value));
|
for de_value in de {
|
||||||
|
de_name.set_if_none(de_value.value());
|
||||||
|
de_aliases.insert(&m.ident, de_value.value());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Parse `#[serde(alias = "foo")]`
|
||||||
|
Meta(NameValue(ref m)) if m.ident == "alias" => {
|
||||||
|
if let Ok(s) = get_lit_str(cx, &m.ident, &m.ident, &m.lit) {
|
||||||
|
de_aliases.insert(&m.ident, s.value());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -753,7 +901,10 @@ impl Variant {
|
|||||||
Meta(NameValue(ref m)) if m.ident == "rename_all" => {
|
Meta(NameValue(ref m)) if m.ident == "rename_all" => {
|
||||||
if let Ok(s) = get_lit_str(cx, &m.ident, &m.ident, &m.lit) {
|
if let Ok(s) = get_lit_str(cx, &m.ident, &m.ident, &m.lit) {
|
||||||
match RenameRule::from_str(&s.value()) {
|
match RenameRule::from_str(&s.value()) {
|
||||||
Ok(rename_rule) => rename_all.set(&m.ident, rename_rule),
|
Ok(rename_rule) => {
|
||||||
|
rename_all_ser_rule.set(&m.ident, rename_rule);
|
||||||
|
rename_all_de_rule.set(&m.ident, rename_rule);
|
||||||
|
}
|
||||||
Err(()) => cx.error_spanned_by(
|
Err(()) => cx.error_spanned_by(
|
||||||
s,
|
s,
|
||||||
format!(
|
format!(
|
||||||
@@ -766,6 +917,42 @@ impl Variant {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Parse `#[serde(rename_all(serialize = "foo", deserialize = "bar"))]`
|
||||||
|
Meta(List(ref m)) if m.ident == "rename_all" => {
|
||||||
|
if let Ok((ser, de)) = get_renames(cx, &m.nested) {
|
||||||
|
if let Some(ser) = ser {
|
||||||
|
match RenameRule::from_str(&ser.value()) {
|
||||||
|
Ok(rename_rule) => {
|
||||||
|
rename_all_ser_rule.set(&m.ident, rename_rule)
|
||||||
|
}
|
||||||
|
Err(()) => cx.error_spanned_by(
|
||||||
|
ser,
|
||||||
|
format!(
|
||||||
|
"unknown rename rule for #[serde(rename_all \
|
||||||
|
= {:?})]",
|
||||||
|
ser.value(),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if let Some(de) = de {
|
||||||
|
match RenameRule::from_str(&de.value()) {
|
||||||
|
Ok(rename_rule) => {
|
||||||
|
rename_all_de_rule.set(&m.ident, rename_rule)
|
||||||
|
}
|
||||||
|
Err(()) => cx.error_spanned_by(
|
||||||
|
de,
|
||||||
|
format!(
|
||||||
|
"unknown rename rule for #[serde(rename_all \
|
||||||
|
= {:?})]",
|
||||||
|
de.value(),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Parse `#[serde(skip)]`
|
// Parse `#[serde(skip)]`
|
||||||
Meta(Word(ref word)) if word == "skip" => {
|
Meta(Word(ref word)) if word == "skip" => {
|
||||||
skip_serializing.set_true(word);
|
skip_serializing.set_true(word);
|
||||||
@@ -864,18 +1051,12 @@ impl Variant {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let ser_name = ser_name.get();
|
|
||||||
let ser_renamed = ser_name.is_some();
|
|
||||||
let de_name = de_name.get();
|
|
||||||
let de_renamed = de_name.is_some();
|
|
||||||
Variant {
|
Variant {
|
||||||
name: Name {
|
name: Name::from_attrs(unraw(&variant.ident), ser_name, de_name, Some(de_aliases)),
|
||||||
serialize: ser_name.unwrap_or_else(|| unraw(&variant.ident)),
|
rename_all_rules: RenameAllRules {
|
||||||
deserialize: de_name.unwrap_or_else(|| unraw(&variant.ident)),
|
serialize: rename_all_ser_rule.get().unwrap_or(RenameRule::None),
|
||||||
|
deserialize: rename_all_de_rule.get().unwrap_or(RenameRule::None),
|
||||||
},
|
},
|
||||||
ser_renamed: ser_renamed,
|
|
||||||
de_renamed: de_renamed,
|
|
||||||
rename_all: rename_all.get().unwrap_or(RenameRule::None),
|
|
||||||
ser_bound: ser_bound.get(),
|
ser_bound: ser_bound.get(),
|
||||||
de_bound: de_bound.get(),
|
de_bound: de_bound.get(),
|
||||||
skip_deserializing: skip_deserializing.get(),
|
skip_deserializing: skip_deserializing.get(),
|
||||||
@@ -891,17 +1072,21 @@ impl Variant {
|
|||||||
&self.name
|
&self.name
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn rename_by_rule(&mut self, rule: &RenameRule) {
|
pub fn aliases(&self) -> Vec<String> {
|
||||||
if !self.ser_renamed {
|
self.name.deserialize_aliases()
|
||||||
self.name.serialize = rule.apply_to_variant(&self.name.serialize);
|
}
|
||||||
|
|
||||||
|
pub fn rename_by_rules(&mut self, rules: &RenameAllRules) {
|
||||||
|
if !self.name.serialize_renamed {
|
||||||
|
self.name.serialize = rules.serialize.apply_to_variant(&self.name.serialize);
|
||||||
}
|
}
|
||||||
if !self.de_renamed {
|
if !self.name.deserialize_renamed {
|
||||||
self.name.deserialize = rule.apply_to_variant(&self.name.deserialize);
|
self.name.deserialize = rules.deserialize.apply_to_variant(&self.name.deserialize);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn rename_all(&self) -> &RenameRule {
|
pub fn rename_all_rules(&self) -> &RenameAllRules {
|
||||||
&self.rename_all
|
&self.rename_all_rules
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn ser_bound(&self) -> Option<&[syn::WherePredicate]> {
|
pub fn ser_bound(&self) -> Option<&[syn::WherePredicate]> {
|
||||||
@@ -936,8 +1121,6 @@ impl Variant {
|
|||||||
/// Represents field attribute information
|
/// Represents field attribute information
|
||||||
pub struct Field {
|
pub struct Field {
|
||||||
name: Name,
|
name: Name,
|
||||||
ser_renamed: bool,
|
|
||||||
de_renamed: bool,
|
|
||||||
skip_serializing: bool,
|
skip_serializing: bool,
|
||||||
skip_deserializing: bool,
|
skip_deserializing: bool,
|
||||||
skip_serializing_if: Option<syn::ExprPath>,
|
skip_serializing_if: Option<syn::ExprPath>,
|
||||||
@@ -982,6 +1165,7 @@ impl Field {
|
|||||||
) -> Self {
|
) -> Self {
|
||||||
let mut ser_name = Attr::none(cx, "rename");
|
let mut ser_name = Attr::none(cx, "rename");
|
||||||
let mut de_name = Attr::none(cx, "rename");
|
let mut de_name = Attr::none(cx, "rename");
|
||||||
|
let mut de_aliases = VecAttr::none(cx, "rename");
|
||||||
let mut skip_serializing = BoolAttr::none(cx, "skip_serializing");
|
let mut skip_serializing = BoolAttr::none(cx, "skip_serializing");
|
||||||
let mut skip_deserializing = BoolAttr::none(cx, "skip_deserializing");
|
let mut skip_deserializing = BoolAttr::none(cx, "skip_deserializing");
|
||||||
let mut skip_serializing_if = Attr::none(cx, "skip_serializing_if");
|
let mut skip_serializing_if = Attr::none(cx, "skip_serializing_if");
|
||||||
@@ -1015,15 +1199,26 @@ impl Field {
|
|||||||
Meta(NameValue(ref m)) if m.ident == "rename" => {
|
Meta(NameValue(ref m)) if m.ident == "rename" => {
|
||||||
if let Ok(s) = get_lit_str(cx, &m.ident, &m.ident, &m.lit) {
|
if let Ok(s) = get_lit_str(cx, &m.ident, &m.ident, &m.lit) {
|
||||||
ser_name.set(&m.ident, s.value());
|
ser_name.set(&m.ident, s.value());
|
||||||
de_name.set(&m.ident, s.value());
|
de_name.set_if_none(s.value());
|
||||||
|
de_aliases.insert(&m.ident, s.value());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse `#[serde(rename(serialize = "foo", deserialize = "bar"))]`
|
// Parse `#[serde(rename(serialize = "foo", deserialize = "bar"))]`
|
||||||
Meta(List(ref m)) if m.ident == "rename" => {
|
Meta(List(ref m)) if m.ident == "rename" => {
|
||||||
if let Ok((ser, de)) = get_renames(cx, &m.nested) {
|
if let Ok((ser, de)) = get_multiple_renames(cx, &m.nested) {
|
||||||
ser_name.set_opt(&m.ident, ser.map(syn::LitStr::value));
|
ser_name.set_opt(&m.ident, ser.map(syn::LitStr::value));
|
||||||
de_name.set_opt(&m.ident, de.map(syn::LitStr::value));
|
for de_value in de {
|
||||||
|
de_name.set_if_none(de_value.value());
|
||||||
|
de_aliases.insert(&m.ident, de_value.value());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Parse `#[serde(alias = "foo")]`
|
||||||
|
Meta(NameValue(ref m)) if m.ident == "alias" => {
|
||||||
|
if let Ok(s) = get_lit_str(cx, &m.ident, &m.ident, &m.lit) {
|
||||||
|
de_aliases.insert(&m.ident, s.value());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1230,17 +1425,8 @@ impl Field {
|
|||||||
collect_lifetimes(&field.ty, &mut borrowed_lifetimes);
|
collect_lifetimes(&field.ty, &mut borrowed_lifetimes);
|
||||||
}
|
}
|
||||||
|
|
||||||
let ser_name = ser_name.get();
|
|
||||||
let ser_renamed = ser_name.is_some();
|
|
||||||
let de_name = de_name.get();
|
|
||||||
let de_renamed = de_name.is_some();
|
|
||||||
Field {
|
Field {
|
||||||
name: Name {
|
name: Name::from_attrs(ident, ser_name, de_name, Some(de_aliases)),
|
||||||
serialize: ser_name.unwrap_or_else(|| ident.clone()),
|
|
||||||
deserialize: de_name.unwrap_or(ident),
|
|
||||||
},
|
|
||||||
ser_renamed: ser_renamed,
|
|
||||||
de_renamed: de_renamed,
|
|
||||||
skip_serializing: skip_serializing.get(),
|
skip_serializing: skip_serializing.get(),
|
||||||
skip_deserializing: skip_deserializing.get(),
|
skip_deserializing: skip_deserializing.get(),
|
||||||
skip_serializing_if: skip_serializing_if.get(),
|
skip_serializing_if: skip_serializing_if.get(),
|
||||||
@@ -1260,12 +1446,16 @@ impl Field {
|
|||||||
&self.name
|
&self.name
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn rename_by_rule(&mut self, rule: &RenameRule) {
|
pub fn aliases(&self) -> Vec<String> {
|
||||||
if !self.ser_renamed {
|
self.name.deserialize_aliases()
|
||||||
self.name.serialize = rule.apply_to_field(&self.name.serialize);
|
}
|
||||||
|
|
||||||
|
pub fn rename_by_rules(&mut self, rules: &RenameAllRules) {
|
||||||
|
if !self.name.serialize_renamed {
|
||||||
|
self.name.serialize = rules.serialize.apply_to_field(&self.name.serialize);
|
||||||
}
|
}
|
||||||
if !self.de_renamed {
|
if !self.name.deserialize_renamed {
|
||||||
self.name.deserialize = rule.apply_to_field(&self.name.deserialize);
|
self.name.deserialize = rules.deserialize.apply_to_field(&self.name.deserialize);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1324,31 +1514,31 @@ impl Field {
|
|||||||
|
|
||||||
type SerAndDe<T> = (Option<T>, Option<T>);
|
type SerAndDe<T> = (Option<T>, Option<T>);
|
||||||
|
|
||||||
fn get_ser_and_de<'a, T, F>(
|
fn get_ser_and_de<'a, 'b, T, F>(
|
||||||
cx: &Ctxt,
|
cx: &'b Ctxt,
|
||||||
attr_name: &'static str,
|
attr_name: &'static str,
|
||||||
metas: &'a Punctuated<syn::NestedMeta, Token![,]>,
|
metas: &'a Punctuated<syn::NestedMeta, Token![,]>,
|
||||||
f: F,
|
f: F,
|
||||||
) -> Result<SerAndDe<T>, ()>
|
) -> Result<(VecAttr<'b, T>, VecAttr<'b, T>), ()>
|
||||||
where
|
where
|
||||||
T: 'a,
|
T: 'a,
|
||||||
F: Fn(&Ctxt, &Ident, &Ident, &'a syn::Lit) -> Result<T, ()>,
|
F: Fn(&Ctxt, &Ident, &Ident, &'a syn::Lit) -> Result<T, ()>,
|
||||||
{
|
{
|
||||||
let mut ser_meta = Attr::none(cx, attr_name);
|
let mut ser_meta = VecAttr::none(cx, attr_name);
|
||||||
let mut de_meta = Attr::none(cx, attr_name);
|
let mut de_meta = VecAttr::none(cx, attr_name);
|
||||||
let attr_name = Ident::new(attr_name, Span::call_site());
|
let attr_name = Ident::new(attr_name, Span::call_site());
|
||||||
|
|
||||||
for meta in metas {
|
for meta in metas {
|
||||||
match *meta {
|
match *meta {
|
||||||
Meta(NameValue(ref meta)) if meta.ident == "serialize" => {
|
Meta(NameValue(ref meta)) if meta.ident == "serialize" => {
|
||||||
if let Ok(v) = f(cx, &attr_name, &meta.ident, &meta.lit) {
|
if let Ok(v) = f(cx, &attr_name, &meta.ident, &meta.lit) {
|
||||||
ser_meta.set(&meta.ident, v);
|
ser_meta.insert(&meta.ident, v);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Meta(NameValue(ref meta)) if meta.ident == "deserialize" => {
|
Meta(NameValue(ref meta)) if meta.ident == "deserialize" => {
|
||||||
if let Ok(v) = f(cx, &attr_name, &meta.ident, &meta.lit) {
|
if let Ok(v) = f(cx, &attr_name, &meta.ident, &meta.lit) {
|
||||||
de_meta.set(&meta.ident, v);
|
de_meta.insert(&meta.ident, v);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1366,21 +1556,31 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok((ser_meta.get(), de_meta.get()))
|
Ok((ser_meta, de_meta))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_renames<'a>(
|
fn get_renames<'a>(
|
||||||
cx: &Ctxt,
|
cx: &Ctxt,
|
||||||
items: &'a Punctuated<syn::NestedMeta, Token![,]>,
|
items: &'a Punctuated<syn::NestedMeta, Token![,]>,
|
||||||
) -> Result<SerAndDe<&'a syn::LitStr>, ()> {
|
) -> Result<SerAndDe<&'a syn::LitStr>, ()> {
|
||||||
get_ser_and_de(cx, "rename", items, get_lit_str)
|
let (ser, de) = try!(get_ser_and_de(cx, "rename", items, get_lit_str));
|
||||||
|
Ok((try!(ser.at_most_one()), try!(de.at_most_one())))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_multiple_renames<'a>(
|
||||||
|
cx: &Ctxt,
|
||||||
|
items: &'a Punctuated<syn::NestedMeta, Token![,]>,
|
||||||
|
) -> Result<(Option<&'a syn::LitStr>, Vec<&'a syn::LitStr>), ()> {
|
||||||
|
let (ser, de) = try!(get_ser_and_de(cx, "rename", items, get_lit_str));
|
||||||
|
Ok((try!(ser.at_most_one()), de.get()))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_where_predicates(
|
fn get_where_predicates(
|
||||||
cx: &Ctxt,
|
cx: &Ctxt,
|
||||||
items: &Punctuated<syn::NestedMeta, Token![,]>,
|
items: &Punctuated<syn::NestedMeta, Token![,]>,
|
||||||
) -> Result<SerAndDe<Vec<syn::WherePredicate>>, ()> {
|
) -> Result<SerAndDe<Vec<syn::WherePredicate>>, ()> {
|
||||||
get_ser_and_de(cx, "bound", items, parse_lit_into_where)
|
let (ser, de) = try!(get_ser_and_de(cx, "bound", items, parse_lit_into_where));
|
||||||
|
Ok((try!(ser.at_most_one()), try!(de.at_most_one())))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_serde_meta_items(attr: &syn::Attribute) -> Option<Vec<syn::NestedMeta>> {
|
pub fn get_serde_meta_items(attr: &syn::Attribute) -> Option<Vec<syn::NestedMeta>> {
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ use std::str::FromStr;
|
|||||||
use self::RenameRule::*;
|
use self::RenameRule::*;
|
||||||
|
|
||||||
/// The different possible ways to change case of fields in a struct, or variants in an enum.
|
/// The different possible ways to change case of fields in a struct, or variants in an enum.
|
||||||
#[derive(PartialEq)]
|
#[derive(Copy, Clone, PartialEq)]
|
||||||
pub enum RenameRule {
|
pub enum RenameRule {
|
||||||
/// Don't apply a default rename rule.
|
/// Don't apply a default rename rule.
|
||||||
None,
|
None,
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
use internals::ast::{Container, Data, Field, Style};
|
use internals::ast::{Container, Data, Field, Style};
|
||||||
use internals::attr::{EnumTag, Identifier};
|
use internals::attr::{Identifier, TagType};
|
||||||
use internals::{Ctxt, Derive};
|
use internals::{Ctxt, Derive};
|
||||||
use syn::{Member, Type};
|
use syn::{Member, Type};
|
||||||
|
|
||||||
@@ -127,7 +127,7 @@ fn check_identifier(cx: &Ctxt, cont: &Container) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Variant with `other` attribute cannot appear in untagged enum
|
// Variant with `other` attribute cannot appear in untagged enum
|
||||||
(_, Identifier::No, true, &EnumTag::None) => {
|
(_, Identifier::No, true, &TagType::None) => {
|
||||||
cx.error_spanned_by(
|
cx.error_spanned_by(
|
||||||
variant.original,
|
variant.original,
|
||||||
"#[serde(other)] cannot appear on untagged enum",
|
"#[serde(other)] cannot appear on untagged enum",
|
||||||
@@ -276,8 +276,8 @@ fn check_internal_tag_field_name_conflict(cx: &Ctxt, cont: &Container) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let tag = match *cont.attrs.tag() {
|
let tag = match *cont.attrs.tag() {
|
||||||
EnumTag::Internal { ref tag } => tag.as_str(),
|
TagType::Internal { ref tag } => tag.as_str(),
|
||||||
EnumTag::External | EnumTag::Adjacent { .. } | EnumTag::None => return,
|
TagType::External | TagType::Adjacent { .. } | TagType::None => return,
|
||||||
};
|
};
|
||||||
|
|
||||||
let diagnose_conflict = || {
|
let diagnose_conflict = || {
|
||||||
@@ -295,12 +295,18 @@ fn check_internal_tag_field_name_conflict(cx: &Ctxt, cont: &Container) {
|
|||||||
let check_de = !field.attrs.skip_deserializing();
|
let check_de = !field.attrs.skip_deserializing();
|
||||||
let name = field.attrs.name();
|
let name = field.attrs.name();
|
||||||
let ser_name = name.serialize_name();
|
let ser_name = name.serialize_name();
|
||||||
let de_name = name.deserialize_name();
|
|
||||||
|
|
||||||
if check_ser && ser_name == tag || check_de && de_name == tag {
|
if check_ser && ser_name == tag {
|
||||||
diagnose_conflict();
|
diagnose_conflict();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for de_name in field.attrs.aliases() {
|
||||||
|
if check_de && de_name == tag {
|
||||||
|
diagnose_conflict();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Style::Unit | Style::Newtype | Style::Tuple => {}
|
Style::Unit | Style::Newtype | Style::Tuple => {}
|
||||||
@@ -312,11 +318,11 @@ fn check_internal_tag_field_name_conflict(cx: &Ctxt, cont: &Container) {
|
|||||||
/// contents tag must differ, for the same reason.
|
/// contents tag must differ, for the same reason.
|
||||||
fn check_adjacent_tag_conflict(cx: &Ctxt, cont: &Container) {
|
fn check_adjacent_tag_conflict(cx: &Ctxt, cont: &Container) {
|
||||||
let (type_tag, content_tag) = match *cont.attrs.tag() {
|
let (type_tag, content_tag) = match *cont.attrs.tag() {
|
||||||
EnumTag::Adjacent {
|
TagType::Adjacent {
|
||||||
ref tag,
|
ref tag,
|
||||||
ref content,
|
ref content,
|
||||||
} => (tag, content),
|
} => (tag, content),
|
||||||
EnumTag::Internal { .. } | EnumTag::External | EnumTag::None => return,
|
TagType::Internal { .. } | TagType::External | TagType::None => return,
|
||||||
};
|
};
|
||||||
|
|
||||||
if type_tag == content_tag {
|
if type_tag == content_tag {
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
//! This crate provides Serde's two derive macros.
|
//! This crate provides Serde's two derive macros.
|
||||||
//!
|
//!
|
||||||
//! ```rust
|
//! ```edition2018
|
||||||
//! # #[macro_use]
|
//! # use serde_derive::{Serialize, Deserialize};
|
||||||
//! # extern crate serde_derive;
|
|
||||||
//! #
|
//! #
|
||||||
//! #[derive(Serialize, Deserialize)]
|
//! #[derive(Serialize, Deserialize)]
|
||||||
//! # struct S;
|
//! # struct S;
|
||||||
@@ -14,10 +13,10 @@
|
|||||||
//!
|
//!
|
||||||
//! [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.82")]
|
#![doc(html_root_url = "https://docs.rs/serde_derive/1.0.85")]
|
||||||
#![cfg_attr(feature = "cargo-clippy", allow(renamed_and_removed_lints))]
|
#![cfg_attr(feature = "cargo-clippy", allow(renamed_and_removed_lints))]
|
||||||
#![cfg_attr(feature = "cargo-clippy", deny(clippy, clippy_pedantic))]
|
#![cfg_attr(feature = "cargo-clippy", deny(clippy, clippy_pedantic))]
|
||||||
// Whitelisted clippy lints
|
// Ignored clippy lints
|
||||||
#![cfg_attr(
|
#![cfg_attr(
|
||||||
feature = "cargo-clippy",
|
feature = "cargo-clippy",
|
||||||
allow(
|
allow(
|
||||||
@@ -26,10 +25,11 @@
|
|||||||
needless_pass_by_value,
|
needless_pass_by_value,
|
||||||
redundant_field_names,
|
redundant_field_names,
|
||||||
too_many_arguments,
|
too_many_arguments,
|
||||||
|
trivially_copy_pass_by_ref,
|
||||||
used_underscore_binding,
|
used_underscore_binding,
|
||||||
)
|
)
|
||||||
)]
|
)]
|
||||||
// Whitelisted clippy_pedantic lints
|
// Ignored clippy_pedantic lints
|
||||||
#![cfg_attr(
|
#![cfg_attr(
|
||||||
feature = "cargo-clippy",
|
feature = "cargo-clippy",
|
||||||
allow(
|
allow(
|
||||||
@@ -40,9 +40,9 @@
|
|||||||
indexing_slicing,
|
indexing_slicing,
|
||||||
items_after_statements,
|
items_after_statements,
|
||||||
match_same_arms,
|
match_same_arms,
|
||||||
|
module_name_repetitions,
|
||||||
similar_names,
|
similar_names,
|
||||||
single_match_else,
|
single_match_else,
|
||||||
stutter,
|
|
||||||
unseparated_literal_suffix,
|
unseparated_literal_suffix,
|
||||||
use_self,
|
use_self,
|
||||||
)
|
)
|
||||||
@@ -69,6 +69,7 @@ mod bound;
|
|||||||
mod fragment;
|
mod fragment;
|
||||||
|
|
||||||
mod de;
|
mod de;
|
||||||
|
mod dummy;
|
||||||
mod pretend;
|
mod pretend;
|
||||||
mod ser;
|
mod ser;
|
||||||
mod try;
|
mod try;
|
||||||
|
|||||||
+27
-26
@@ -3,11 +3,11 @@ use syn::spanned::Spanned;
|
|||||||
use syn::{self, Ident, Index, Member};
|
use syn::{self, Ident, Index, Member};
|
||||||
|
|
||||||
use bound;
|
use bound;
|
||||||
|
use dummy;
|
||||||
use fragment::{Fragment, Match, Stmts};
|
use fragment::{Fragment, Match, Stmts};
|
||||||
use internals::ast::{Container, Data, Field, Style, Variant};
|
use internals::ast::{Container, Data, Field, Style, Variant};
|
||||||
use internals::{attr, Ctxt, Derive};
|
use internals::{attr, Ctxt, Derive};
|
||||||
use pretend;
|
use pretend;
|
||||||
use try;
|
|
||||||
|
|
||||||
pub fn expand_derive_serialize(input: &syn::DeriveInput) -> Result<TokenStream, Vec<syn::Error>> {
|
pub fn expand_derive_serialize(input: &syn::DeriveInput) -> Result<TokenStream, Vec<syn::Error>> {
|
||||||
let ctxt = Ctxt::new();
|
let ctxt = Ctxt::new();
|
||||||
@@ -21,11 +21,6 @@ pub fn expand_derive_serialize(input: &syn::DeriveInput) -> Result<TokenStream,
|
|||||||
let ident = &cont.ident;
|
let ident = &cont.ident;
|
||||||
let params = Parameters::new(&cont);
|
let params = Parameters::new(&cont);
|
||||||
let (impl_generics, ty_generics, where_clause) = params.generics.split_for_impl();
|
let (impl_generics, ty_generics, where_clause) = params.generics.split_for_impl();
|
||||||
let suffix = ident.to_string().trim_left_matches("r#").to_owned();
|
|
||||||
let dummy_const = Ident::new(
|
|
||||||
&format!("_IMPL_SERIALIZE_FOR_{}", suffix),
|
|
||||||
Span::call_site(),
|
|
||||||
);
|
|
||||||
let body = Stmts(serialize_body(&cont, ¶ms));
|
let body = Stmts(serialize_body(&cont, ¶ms));
|
||||||
|
|
||||||
let impl_block = if let Some(remote) = cont.attrs.remote() {
|
let impl_block = if let Some(remote) = cont.attrs.remote() {
|
||||||
@@ -56,19 +51,7 @@ pub fn expand_derive_serialize(input: &syn::DeriveInput) -> Result<TokenStream,
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let try_replacement = try::replacement();
|
Ok(dummy::wrap_in_const("SERIALIZE", ident, impl_block))
|
||||||
let generated = quote! {
|
|
||||||
#[allow(non_upper_case_globals, unused_attributes, unused_qualifications)]
|
|
||||||
const #dummy_const: () = {
|
|
||||||
#[allow(unknown_lints)]
|
|
||||||
#[cfg_attr(feature = "cargo-clippy", allow(useless_attribute))]
|
|
||||||
#[allow(rust_2018_idioms)]
|
|
||||||
extern crate serde as _serde;
|
|
||||||
#try_replacement
|
|
||||||
#impl_block
|
|
||||||
};
|
|
||||||
};
|
|
||||||
Ok(generated)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn precondition(cx: &Ctxt, cont: &Container) {
|
fn precondition(cx: &Ctxt, cont: &Container) {
|
||||||
@@ -311,17 +294,32 @@ fn serialize_struct_as_struct(
|
|||||||
fields: &[Field],
|
fields: &[Field],
|
||||||
cattrs: &attr::Container,
|
cattrs: &attr::Container,
|
||||||
) -> Fragment {
|
) -> Fragment {
|
||||||
let serialize_fields =
|
let mut serialize_fields =
|
||||||
serialize_struct_visitor(fields, params, false, &StructTrait::SerializeStruct);
|
serialize_struct_visitor(fields, params, false, &StructTrait::SerializeStruct);
|
||||||
|
|
||||||
let type_name = cattrs.name().serialize_name();
|
let type_name = cattrs.name().serialize_name();
|
||||||
|
|
||||||
|
let additional_field_count: usize = match *cattrs.tag() {
|
||||||
|
attr::TagType::Internal { ref tag } => {
|
||||||
|
let func = StructTrait::SerializeStruct.serialize_field(Span::call_site());
|
||||||
|
serialize_fields.insert(
|
||||||
|
0,
|
||||||
|
quote! {
|
||||||
|
try!(#func(&mut __serde_state, #tag, #type_name));
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
1
|
||||||
|
}
|
||||||
|
_ => 0,
|
||||||
|
};
|
||||||
|
|
||||||
let mut serialized_fields = fields
|
let mut serialized_fields = fields
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|&field| !field.attrs.skip_serializing())
|
.filter(|&field| !field.attrs.skip_serializing())
|
||||||
.peekable();
|
.peekable();
|
||||||
|
|
||||||
let let_mut = mut_if(serialized_fields.peek().is_some());
|
let let_mut = mut_if(serialized_fields.peek().is_some() || additional_field_count > 0);
|
||||||
|
|
||||||
let len = serialized_fields
|
let len = serialized_fields
|
||||||
.map(|field| match field.attrs.skip_serializing_if() {
|
.map(|field| match field.attrs.skip_serializing_if() {
|
||||||
@@ -331,7 +329,10 @@ fn serialize_struct_as_struct(
|
|||||||
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!(#additional_field_count),
|
||||||
|
|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));
|
||||||
@@ -452,17 +453,17 @@ fn serialize_variant(
|
|||||||
};
|
};
|
||||||
|
|
||||||
let body = Match(match *cattrs.tag() {
|
let body = Match(match *cattrs.tag() {
|
||||||
attr::EnumTag::External => {
|
attr::TagType::External => {
|
||||||
serialize_externally_tagged_variant(params, variant, variant_index, cattrs)
|
serialize_externally_tagged_variant(params, variant, variant_index, cattrs)
|
||||||
}
|
}
|
||||||
attr::EnumTag::Internal { ref tag } => {
|
attr::TagType::Internal { ref tag } => {
|
||||||
serialize_internally_tagged_variant(params, variant, cattrs, tag)
|
serialize_internally_tagged_variant(params, variant, cattrs, tag)
|
||||||
}
|
}
|
||||||
attr::EnumTag::Adjacent {
|
attr::TagType::Adjacent {
|
||||||
ref tag,
|
ref tag,
|
||||||
ref content,
|
ref content,
|
||||||
} => serialize_adjacently_tagged_variant(params, variant, cattrs, tag, content),
|
} => serialize_adjacently_tagged_variant(params, variant, cattrs, tag, content),
|
||||||
attr::EnumTag::None => serialize_untagged_variant(params, variant, cattrs),
|
attr::TagType::None => serialize_untagged_variant(params, variant, cattrs),
|
||||||
});
|
});
|
||||||
|
|
||||||
quote! {
|
quote! {
|
||||||
|
|||||||
@@ -4,9 +4,8 @@
|
|||||||
feature = "cargo-clippy",
|
feature = "cargo-clippy",
|
||||||
allow(
|
allow(
|
||||||
cyclomatic_complexity,
|
cyclomatic_complexity,
|
||||||
doc_markdown,
|
redundant_field_names,
|
||||||
match_same_arms,
|
trivially_copy_pass_by_ref
|
||||||
redundant_field_names
|
|
||||||
)
|
)
|
||||||
)]
|
)]
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "serde_test"
|
name = "serde_test"
|
||||||
version = "1.0.82" # remember to update html_root_url
|
version = "1.0.85" # 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"
|
||||||
@@ -15,7 +15,7 @@ include = ["Cargo.toml", "src/**/*.rs", "crates-io.md", "README.md", "LICENSE-AP
|
|||||||
serde = { version = "1.0.60", path = "../serde" }
|
serde = { version = "1.0.60", path = "../serde" }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
serde = { version = "1.0", path = "../serde", features = ["rc"] }
|
serde = { version = "1.0", path = "../serde" }
|
||||||
serde_derive = { version = "1.0", path = "../serde_derive" }
|
serde_derive = { version = "1.0", path = "../serde_derive" }
|
||||||
|
|
||||||
[badges]
|
[badges]
|
||||||
|
|||||||
+28
-52
@@ -8,13 +8,8 @@ use std::fmt::Debug;
|
|||||||
|
|
||||||
/// Runs both `assert_ser_tokens` and `assert_de_tokens`.
|
/// Runs both `assert_ser_tokens` and `assert_de_tokens`.
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```edition2018
|
||||||
/// # #[macro_use]
|
/// # use serde::{Serialize, Deserialize};
|
||||||
/// # extern crate serde_derive;
|
|
||||||
/// #
|
|
||||||
/// # extern crate serde;
|
|
||||||
/// # extern crate serde_test;
|
|
||||||
/// #
|
|
||||||
/// # use serde_test::{assert_tokens, Token};
|
/// # use serde_test::{assert_tokens, Token};
|
||||||
/// #
|
/// #
|
||||||
/// # fn main() {
|
/// # fn main() {
|
||||||
@@ -45,13 +40,8 @@ where
|
|||||||
|
|
||||||
/// Asserts that `value` serializes to the given `tokens`.
|
/// Asserts that `value` serializes to the given `tokens`.
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```edition2018
|
||||||
/// # #[macro_use]
|
/// # use serde::{Serialize, Deserialize};
|
||||||
/// # extern crate serde_derive;
|
|
||||||
/// #
|
|
||||||
/// # extern crate serde;
|
|
||||||
/// # extern crate serde_test;
|
|
||||||
/// #
|
|
||||||
/// # use serde_test::{assert_ser_tokens, Token};
|
/// # use serde_test::{assert_ser_tokens, Token};
|
||||||
/// #
|
/// #
|
||||||
/// # fn main() {
|
/// # fn main() {
|
||||||
@@ -90,16 +80,11 @@ where
|
|||||||
/// Asserts that `value` serializes to the given `tokens`, and then yields
|
/// Asserts that `value` serializes to the given `tokens`, and then yields
|
||||||
/// `error`.
|
/// `error`.
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```edition2018
|
||||||
/// # #[macro_use]
|
|
||||||
/// # extern crate serde_derive;
|
|
||||||
/// #
|
|
||||||
/// # extern crate serde_test;
|
|
||||||
/// #
|
|
||||||
/// # fn main() {
|
|
||||||
/// use std::sync::{Arc, Mutex};
|
/// use std::sync::{Arc, Mutex};
|
||||||
/// use std::thread;
|
/// use std::thread;
|
||||||
///
|
///
|
||||||
|
/// use serde::Serialize;
|
||||||
/// use serde_test::{assert_ser_tokens_error, Token};
|
/// use serde_test::{assert_ser_tokens_error, Token};
|
||||||
///
|
///
|
||||||
/// #[derive(Serialize)]
|
/// #[derive(Serialize)]
|
||||||
@@ -107,26 +92,27 @@ where
|
|||||||
/// lock: Arc<Mutex<u32>>,
|
/// lock: Arc<Mutex<u32>>,
|
||||||
/// }
|
/// }
|
||||||
///
|
///
|
||||||
/// let example = Example { lock: Arc::new(Mutex::new(0)) };
|
/// fn main() {
|
||||||
/// let lock = example.lock.clone();
|
/// let example = Example { lock: Arc::new(Mutex::new(0)) };
|
||||||
|
/// let lock = example.lock.clone();
|
||||||
///
|
///
|
||||||
/// let _ = thread::spawn(move || {
|
/// let _ = thread::spawn(move || {
|
||||||
/// // This thread will acquire the mutex first, unwrapping the result
|
/// // This thread will acquire the mutex first, unwrapping the result
|
||||||
/// // of `lock` because the lock has not been poisoned.
|
/// // of `lock` because the lock has not been poisoned.
|
||||||
/// let _guard = lock.lock().unwrap();
|
/// let _guard = lock.lock().unwrap();
|
||||||
///
|
///
|
||||||
/// // This panic while holding the lock (`_guard` is in scope) will
|
/// // This panic while holding the lock (`_guard` is in scope) will
|
||||||
/// // poison the mutex.
|
/// // poison the mutex.
|
||||||
/// panic!()
|
/// panic!()
|
||||||
/// }).join();
|
/// }).join();
|
||||||
///
|
///
|
||||||
/// let expected = &[
|
/// let expected = &[
|
||||||
/// Token::Struct { name: "Example", len: 1 },
|
/// Token::Struct { name: "Example", len: 1 },
|
||||||
/// Token::Str("lock"),
|
/// Token::Str("lock"),
|
||||||
/// ];
|
/// ];
|
||||||
/// let error = "lock poison error while serializing";
|
/// let error = "lock poison error while serializing";
|
||||||
/// assert_ser_tokens_error(&example, expected, error);
|
/// assert_ser_tokens_error(&example, expected, error);
|
||||||
/// # }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
pub fn assert_ser_tokens_error<T>(value: &T, tokens: &[Token], error: &str)
|
pub fn assert_ser_tokens_error<T>(value: &T, tokens: &[Token], error: &str)
|
||||||
where
|
where
|
||||||
@@ -145,13 +131,8 @@ where
|
|||||||
|
|
||||||
/// Asserts that the given `tokens` deserialize into `value`.
|
/// Asserts that the given `tokens` deserialize into `value`.
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```edition2018
|
||||||
/// # #[macro_use]
|
/// # use serde::{Serialize, Deserialize};
|
||||||
/// # extern crate serde_derive;
|
|
||||||
/// #
|
|
||||||
/// # extern crate serde;
|
|
||||||
/// # extern crate serde_test;
|
|
||||||
/// #
|
|
||||||
/// # use serde_test::{assert_de_tokens, Token};
|
/// # use serde_test::{assert_de_tokens, Token};
|
||||||
/// #
|
/// #
|
||||||
/// # fn main() {
|
/// # fn main() {
|
||||||
@@ -205,13 +186,8 @@ where
|
|||||||
|
|
||||||
/// Asserts that the given `tokens` yield `error` when deserializing.
|
/// Asserts that the given `tokens` yield `error` when deserializing.
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```edition2018
|
||||||
/// # #[macro_use]
|
/// # use serde::{Serialize, Deserialize};
|
||||||
/// # extern crate serde_derive;
|
|
||||||
/// #
|
|
||||||
/// # extern crate serde;
|
|
||||||
/// # extern crate serde_test;
|
|
||||||
/// #
|
|
||||||
/// # use serde_test::{assert_de_tokens_error, Token};
|
/// # use serde_test::{assert_de_tokens_error, Token};
|
||||||
/// #
|
/// #
|
||||||
/// # fn main() {
|
/// # fn main() {
|
||||||
|
|||||||
@@ -14,10 +14,7 @@ pub struct Compact<T: ?Sized>(T);
|
|||||||
/// Trait to determine whether a value is represented in human-readable or
|
/// Trait to determine whether a value is represented in human-readable or
|
||||||
/// compact form.
|
/// compact form.
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```edition2018
|
||||||
/// extern crate serde;
|
|
||||||
/// extern crate serde_test;
|
|
||||||
///
|
|
||||||
/// use serde::{Deserialize, Deserializer, Serialize, Serializer};
|
/// use serde::{Deserialize, Deserializer, Serialize, Serializer};
|
||||||
/// use serde_test::{assert_tokens, Configure, Token};
|
/// use serde_test::{assert_tokens, Configure, Token};
|
||||||
///
|
///
|
||||||
|
|||||||
+7
-16
@@ -24,19 +24,10 @@
|
|||||||
//!
|
//!
|
||||||
//! [`linked-hash-map`]: https://github.com/contain-rs/linked-hash-map
|
//! [`linked-hash-map`]: https://github.com/contain-rs/linked-hash-map
|
||||||
//!
|
//!
|
||||||
//! ```rust
|
//! ```edition2018
|
||||||
//! # extern crate serde;
|
//! # const IGNORE: &str = stringify! {
|
||||||
//! #
|
|
||||||
//! # macro_rules! ignore {
|
|
||||||
//! # ($($tt:tt)+) => {}
|
|
||||||
//! # }
|
|
||||||
//! #
|
|
||||||
//! # ignore! {
|
|
||||||
//! extern crate linked_hash_map;
|
|
||||||
//! use linked_hash_map::LinkedHashMap;
|
//! use linked_hash_map::LinkedHashMap;
|
||||||
//! # }
|
//! # };
|
||||||
//!
|
|
||||||
//! extern crate serde_test;
|
|
||||||
//! use serde_test::{Token, assert_tokens};
|
//! use serde_test::{Token, assert_tokens};
|
||||||
//!
|
//!
|
||||||
//! # use std::fmt;
|
//! # use std::fmt;
|
||||||
@@ -153,19 +144,19 @@
|
|||||||
//! # }
|
//! # }
|
||||||
//! ```
|
//! ```
|
||||||
|
|
||||||
#![doc(html_root_url = "https://docs.rs/serde_test/1.0.82")]
|
#![doc(html_root_url = "https://docs.rs/serde_test/1.0.85")]
|
||||||
#![cfg_attr(feature = "cargo-clippy", allow(renamed_and_removed_lints))]
|
#![cfg_attr(feature = "cargo-clippy", allow(renamed_and_removed_lints))]
|
||||||
#![cfg_attr(feature = "cargo-clippy", deny(clippy, clippy_pedantic))]
|
#![cfg_attr(feature = "cargo-clippy", deny(clippy, clippy_pedantic))]
|
||||||
// Whitelisted clippy lints
|
// Ignored clippy lints
|
||||||
#![cfg_attr(feature = "cargo-clippy", allow(float_cmp))]
|
#![cfg_attr(feature = "cargo-clippy", allow(float_cmp))]
|
||||||
// Whitelisted clippy_pedantic lints
|
// Ignored clippy_pedantic lints
|
||||||
#![cfg_attr(
|
#![cfg_attr(
|
||||||
feature = "cargo-clippy",
|
feature = "cargo-clippy",
|
||||||
allow(
|
allow(
|
||||||
empty_line_after_outer_attr,
|
empty_line_after_outer_attr,
|
||||||
missing_docs_in_private_items,
|
missing_docs_in_private_items,
|
||||||
|
module_name_repetitions,
|
||||||
redundant_field_names,
|
redundant_field_names,
|
||||||
stutter,
|
|
||||||
use_debug,
|
use_debug,
|
||||||
use_self
|
use_self
|
||||||
)
|
)
|
||||||
|
|||||||
+39
-84
@@ -4,7 +4,7 @@ use std::fmt::{self, Debug, Display};
|
|||||||
pub enum Token {
|
pub enum Token {
|
||||||
/// A serialized `bool`.
|
/// A serialized `bool`.
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```edition2018
|
||||||
/// # use serde_test::{assert_tokens, Token};
|
/// # use serde_test::{assert_tokens, Token};
|
||||||
/// #
|
/// #
|
||||||
/// assert_tokens(&true, &[Token::Bool(true)]);
|
/// assert_tokens(&true, &[Token::Bool(true)]);
|
||||||
@@ -13,7 +13,7 @@ pub enum Token {
|
|||||||
|
|
||||||
/// A serialized `i8`.
|
/// A serialized `i8`.
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```edition2018
|
||||||
/// # use serde_test::{assert_tokens, Token};
|
/// # use serde_test::{assert_tokens, Token};
|
||||||
/// #
|
/// #
|
||||||
/// assert_tokens(&0i8, &[Token::I8(0)]);
|
/// assert_tokens(&0i8, &[Token::I8(0)]);
|
||||||
@@ -22,7 +22,7 @@ pub enum Token {
|
|||||||
|
|
||||||
/// A serialized `i16`.
|
/// A serialized `i16`.
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```edition2018
|
||||||
/// # use serde_test::{assert_tokens, Token};
|
/// # use serde_test::{assert_tokens, Token};
|
||||||
/// #
|
/// #
|
||||||
/// assert_tokens(&0i16, &[Token::I16(0)]);
|
/// assert_tokens(&0i16, &[Token::I16(0)]);
|
||||||
@@ -31,7 +31,7 @@ pub enum Token {
|
|||||||
|
|
||||||
/// A serialized `i32`.
|
/// A serialized `i32`.
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```edition2018
|
||||||
/// # use serde_test::{assert_tokens, Token};
|
/// # use serde_test::{assert_tokens, Token};
|
||||||
/// #
|
/// #
|
||||||
/// assert_tokens(&0i32, &[Token::I32(0)]);
|
/// assert_tokens(&0i32, &[Token::I32(0)]);
|
||||||
@@ -40,7 +40,7 @@ pub enum Token {
|
|||||||
|
|
||||||
/// A serialized `i64`.
|
/// A serialized `i64`.
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```edition2018
|
||||||
/// # use serde_test::{assert_tokens, Token};
|
/// # use serde_test::{assert_tokens, Token};
|
||||||
/// #
|
/// #
|
||||||
/// assert_tokens(&0i64, &[Token::I64(0)]);
|
/// assert_tokens(&0i64, &[Token::I64(0)]);
|
||||||
@@ -49,7 +49,7 @@ pub enum Token {
|
|||||||
|
|
||||||
/// A serialized `u8`.
|
/// A serialized `u8`.
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```edition2018
|
||||||
/// # use serde_test::{assert_tokens, Token};
|
/// # use serde_test::{assert_tokens, Token};
|
||||||
/// #
|
/// #
|
||||||
/// assert_tokens(&0u8, &[Token::U8(0)]);
|
/// assert_tokens(&0u8, &[Token::U8(0)]);
|
||||||
@@ -58,7 +58,7 @@ pub enum Token {
|
|||||||
|
|
||||||
/// A serialized `u16`.
|
/// A serialized `u16`.
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```edition2018
|
||||||
/// # use serde_test::{assert_tokens, Token};
|
/// # use serde_test::{assert_tokens, Token};
|
||||||
/// #
|
/// #
|
||||||
/// assert_tokens(&0u16, &[Token::U16(0)]);
|
/// assert_tokens(&0u16, &[Token::U16(0)]);
|
||||||
@@ -67,7 +67,7 @@ pub enum Token {
|
|||||||
|
|
||||||
/// A serialized `u32`.
|
/// A serialized `u32`.
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```edition2018
|
||||||
/// # use serde_test::{assert_tokens, Token};
|
/// # use serde_test::{assert_tokens, Token};
|
||||||
/// #
|
/// #
|
||||||
/// assert_tokens(&0u32, &[Token::U32(0)]);
|
/// assert_tokens(&0u32, &[Token::U32(0)]);
|
||||||
@@ -76,7 +76,7 @@ pub enum Token {
|
|||||||
|
|
||||||
/// A serialized `u64`.
|
/// A serialized `u64`.
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```edition2018
|
||||||
/// # use serde_test::{assert_tokens, Token};
|
/// # use serde_test::{assert_tokens, Token};
|
||||||
/// #
|
/// #
|
||||||
/// assert_tokens(&0u64, &[Token::U64(0)]);
|
/// assert_tokens(&0u64, &[Token::U64(0)]);
|
||||||
@@ -85,7 +85,7 @@ pub enum Token {
|
|||||||
|
|
||||||
/// A serialized `f32`.
|
/// A serialized `f32`.
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```edition2018
|
||||||
/// # use serde_test::{assert_tokens, Token};
|
/// # use serde_test::{assert_tokens, Token};
|
||||||
/// #
|
/// #
|
||||||
/// assert_tokens(&0f32, &[Token::F32(0.0)]);
|
/// assert_tokens(&0f32, &[Token::F32(0.0)]);
|
||||||
@@ -94,7 +94,7 @@ pub enum Token {
|
|||||||
|
|
||||||
/// A serialized `f64`.
|
/// A serialized `f64`.
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```edition2018
|
||||||
/// # use serde_test::{assert_tokens, Token};
|
/// # use serde_test::{assert_tokens, Token};
|
||||||
/// #
|
/// #
|
||||||
/// assert_tokens(&0f64, &[Token::F64(0.0)]);
|
/// assert_tokens(&0f64, &[Token::F64(0.0)]);
|
||||||
@@ -103,7 +103,7 @@ pub enum Token {
|
|||||||
|
|
||||||
/// A serialized `char`.
|
/// A serialized `char`.
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```edition2018
|
||||||
/// # use serde_test::{assert_tokens, Token};
|
/// # use serde_test::{assert_tokens, Token};
|
||||||
/// #
|
/// #
|
||||||
/// assert_tokens(&'\n', &[Token::Char('\n')]);
|
/// assert_tokens(&'\n', &[Token::Char('\n')]);
|
||||||
@@ -112,7 +112,7 @@ pub enum Token {
|
|||||||
|
|
||||||
/// A serialized `str`.
|
/// A serialized `str`.
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```edition2018
|
||||||
/// # use serde_test::{assert_tokens, Token};
|
/// # use serde_test::{assert_tokens, Token};
|
||||||
/// #
|
/// #
|
||||||
/// let s = String::from("transient");
|
/// let s = String::from("transient");
|
||||||
@@ -122,7 +122,7 @@ pub enum Token {
|
|||||||
|
|
||||||
/// A borrowed `str`.
|
/// A borrowed `str`.
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```edition2018
|
||||||
/// # use serde_test::{assert_tokens, Token};
|
/// # use serde_test::{assert_tokens, Token};
|
||||||
/// #
|
/// #
|
||||||
/// let s: &str = "borrowed";
|
/// let s: &str = "borrowed";
|
||||||
@@ -132,7 +132,7 @@ pub enum Token {
|
|||||||
|
|
||||||
/// A serialized `String`.
|
/// A serialized `String`.
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```edition2018
|
||||||
/// # use serde_test::{assert_tokens, Token};
|
/// # use serde_test::{assert_tokens, Token};
|
||||||
/// #
|
/// #
|
||||||
/// let s = String::from("owned");
|
/// let s = String::from("owned");
|
||||||
@@ -151,7 +151,7 @@ pub enum Token {
|
|||||||
|
|
||||||
/// A serialized `Option<T>` containing none.
|
/// A serialized `Option<T>` containing none.
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```edition2018
|
||||||
/// # use serde_test::{assert_tokens, Token};
|
/// # use serde_test::{assert_tokens, Token};
|
||||||
/// #
|
/// #
|
||||||
/// let opt = None::<char>;
|
/// let opt = None::<char>;
|
||||||
@@ -163,7 +163,7 @@ pub enum Token {
|
|||||||
///
|
///
|
||||||
/// The tokens of the value follow after this header.
|
/// The tokens of the value follow after this header.
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```edition2018
|
||||||
/// # use serde_test::{assert_tokens, Token};
|
/// # use serde_test::{assert_tokens, Token};
|
||||||
/// #
|
/// #
|
||||||
/// let opt = Some('c');
|
/// let opt = Some('c');
|
||||||
@@ -176,7 +176,7 @@ pub enum Token {
|
|||||||
|
|
||||||
/// A serialized `()`.
|
/// A serialized `()`.
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```edition2018
|
||||||
/// # use serde_test::{assert_tokens, Token};
|
/// # use serde_test::{assert_tokens, Token};
|
||||||
/// #
|
/// #
|
||||||
/// assert_tokens(&(), &[Token::Unit]);
|
/// assert_tokens(&(), &[Token::Unit]);
|
||||||
@@ -185,13 +185,8 @@ pub enum Token {
|
|||||||
|
|
||||||
/// A serialized unit struct of the given name.
|
/// A serialized unit struct of the given name.
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```edition2018
|
||||||
/// # #[macro_use]
|
/// # use serde::{Serialize, Deserialize};
|
||||||
/// # extern crate serde_derive;
|
|
||||||
/// #
|
|
||||||
/// # extern crate serde;
|
|
||||||
/// # extern crate serde_test;
|
|
||||||
/// #
|
|
||||||
/// # use serde_test::{assert_tokens, Token};
|
/// # use serde_test::{assert_tokens, Token};
|
||||||
/// #
|
/// #
|
||||||
/// # fn main() {
|
/// # fn main() {
|
||||||
@@ -205,13 +200,8 @@ pub enum Token {
|
|||||||
|
|
||||||
/// A unit variant of an enum.
|
/// A unit variant of an enum.
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```edition2018
|
||||||
/// # #[macro_use]
|
/// # use serde::{Serialize, Deserialize};
|
||||||
/// # extern crate serde_derive;
|
|
||||||
/// #
|
|
||||||
/// # extern crate serde;
|
|
||||||
/// # extern crate serde_test;
|
|
||||||
/// #
|
|
||||||
/// # use serde_test::{assert_tokens, Token};
|
/// # use serde_test::{assert_tokens, Token};
|
||||||
/// #
|
/// #
|
||||||
/// # fn main() {
|
/// # fn main() {
|
||||||
@@ -233,13 +223,8 @@ pub enum Token {
|
|||||||
///
|
///
|
||||||
/// After this header is the value contained in the newtype struct.
|
/// After this header is the value contained in the newtype struct.
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```edition2018
|
||||||
/// # #[macro_use]
|
/// # use serde::{Serialize, Deserialize};
|
||||||
/// # extern crate serde_derive;
|
|
||||||
/// #
|
|
||||||
/// # extern crate serde;
|
|
||||||
/// # extern crate serde_test;
|
|
||||||
/// #
|
|
||||||
/// # use serde_test::{assert_tokens, Token};
|
/// # use serde_test::{assert_tokens, Token};
|
||||||
/// #
|
/// #
|
||||||
/// # fn main() {
|
/// # fn main() {
|
||||||
@@ -259,13 +244,8 @@ pub enum Token {
|
|||||||
///
|
///
|
||||||
/// After this header is the value contained in the newtype variant.
|
/// After this header is the value contained in the newtype variant.
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```edition2018
|
||||||
/// # #[macro_use]
|
/// # use serde::{Serialize, Deserialize};
|
||||||
/// # extern crate serde_derive;
|
|
||||||
/// #
|
|
||||||
/// # extern crate serde;
|
|
||||||
/// # extern crate serde_test;
|
|
||||||
/// #
|
|
||||||
/// # use serde_test::{assert_tokens, Token};
|
/// # use serde_test::{assert_tokens, Token};
|
||||||
/// #
|
/// #
|
||||||
/// # fn main() {
|
/// # fn main() {
|
||||||
@@ -291,7 +271,7 @@ pub enum Token {
|
|||||||
/// After this header are the elements of the sequence, followed by
|
/// After this header are the elements of the sequence, followed by
|
||||||
/// `SeqEnd`.
|
/// `SeqEnd`.
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```edition2018
|
||||||
/// # use serde_test::{assert_tokens, Token};
|
/// # use serde_test::{assert_tokens, Token};
|
||||||
/// #
|
/// #
|
||||||
/// let vec = vec!['a', 'b', 'c'];
|
/// let vec = vec!['a', 'b', 'c'];
|
||||||
@@ -312,7 +292,7 @@ pub enum Token {
|
|||||||
///
|
///
|
||||||
/// After this header are the elements of the tuple, followed by `TupleEnd`.
|
/// After this header are the elements of the tuple, followed by `TupleEnd`.
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```edition2018
|
||||||
/// # use serde_test::{assert_tokens, Token};
|
/// # use serde_test::{assert_tokens, Token};
|
||||||
/// #
|
/// #
|
||||||
/// let tuple = ('a', 100);
|
/// let tuple = ('a', 100);
|
||||||
@@ -333,13 +313,8 @@ pub enum Token {
|
|||||||
/// After this header are the fields of the tuple struct, followed by
|
/// After this header are the fields of the tuple struct, followed by
|
||||||
/// `TupleStructEnd`.
|
/// `TupleStructEnd`.
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```edition2018
|
||||||
/// # #[macro_use]
|
/// # use serde::{Serialize, Deserialize};
|
||||||
/// # extern crate serde_derive;
|
|
||||||
/// #
|
|
||||||
/// # extern crate serde;
|
|
||||||
/// # extern crate serde_test;
|
|
||||||
/// #
|
|
||||||
/// # use serde_test::{assert_tokens, Token};
|
/// # use serde_test::{assert_tokens, Token};
|
||||||
/// #
|
/// #
|
||||||
/// # fn main() {
|
/// # fn main() {
|
||||||
@@ -365,13 +340,8 @@ pub enum Token {
|
|||||||
/// After this header are the fields of the tuple variant, followed by
|
/// After this header are the fields of the tuple variant, followed by
|
||||||
/// `TupleVariantEnd`.
|
/// `TupleVariantEnd`.
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```edition2018
|
||||||
/// # #[macro_use]
|
/// # use serde::{Serialize, Deserialize};
|
||||||
/// # extern crate serde_derive;
|
|
||||||
/// #
|
|
||||||
/// # extern crate serde;
|
|
||||||
/// # extern crate serde_test;
|
|
||||||
/// #
|
|
||||||
/// # use serde_test::{assert_tokens, Token};
|
/// # use serde_test::{assert_tokens, Token};
|
||||||
/// #
|
/// #
|
||||||
/// # fn main() {
|
/// # fn main() {
|
||||||
@@ -402,7 +372,7 @@ pub enum Token {
|
|||||||
///
|
///
|
||||||
/// After this header are the entries of the map, followed by `MapEnd`.
|
/// After this header are the entries of the map, followed by `MapEnd`.
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```edition2018
|
||||||
/// # use serde_test::{assert_tokens, Token};
|
/// # use serde_test::{assert_tokens, Token};
|
||||||
/// #
|
/// #
|
||||||
/// use std::collections::BTreeMap;
|
/// use std::collections::BTreeMap;
|
||||||
@@ -429,13 +399,8 @@ pub enum Token {
|
|||||||
///
|
///
|
||||||
/// After this header are the fields of the struct, followed by `StructEnd`.
|
/// After this header are the fields of the struct, followed by `StructEnd`.
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```edition2018
|
||||||
/// # #[macro_use]
|
/// # use serde::{Serialize, Deserialize};
|
||||||
/// # extern crate serde_derive;
|
|
||||||
/// #
|
|
||||||
/// # extern crate serde;
|
|
||||||
/// # extern crate serde_test;
|
|
||||||
/// #
|
|
||||||
/// # use serde_test::{assert_tokens, Token};
|
/// # use serde_test::{assert_tokens, Token};
|
||||||
/// #
|
/// #
|
||||||
/// # fn main() {
|
/// # fn main() {
|
||||||
@@ -466,13 +431,8 @@ pub enum Token {
|
|||||||
/// After this header are the fields of the struct variant, followed by
|
/// After this header are the fields of the struct variant, followed by
|
||||||
/// `StructVariantEnd`.
|
/// `StructVariantEnd`.
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```edition2018
|
||||||
/// # #[macro_use]
|
/// # use serde::{Serialize, Deserialize};
|
||||||
/// # extern crate serde_derive;
|
|
||||||
/// #
|
|
||||||
/// # extern crate serde;
|
|
||||||
/// # extern crate serde_test;
|
|
||||||
/// #
|
|
||||||
/// # use serde_test::{assert_tokens, Token};
|
/// # use serde_test::{assert_tokens, Token};
|
||||||
/// #
|
/// #
|
||||||
/// # fn main() {
|
/// # fn main() {
|
||||||
@@ -501,13 +461,8 @@ pub enum Token {
|
|||||||
|
|
||||||
/// The header to an enum of the given name.
|
/// The header to an enum of the given name.
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```edition2018
|
||||||
/// # #[macro_use]
|
/// # use serde::{Serialize, Deserialize};
|
||||||
/// # extern crate serde_derive;
|
|
||||||
/// #
|
|
||||||
/// # extern crate serde;
|
|
||||||
/// # extern crate serde_test;
|
|
||||||
/// #
|
|
||||||
/// # use serde_test::{assert_tokens, Token};
|
/// # use serde_test::{assert_tokens, Token};
|
||||||
/// #
|
/// #
|
||||||
/// # fn main() {
|
/// # fn main() {
|
||||||
|
|||||||
@@ -2,15 +2,17 @@
|
|||||||
name = "serde_test_suite"
|
name = "serde_test_suite"
|
||||||
version = "0.0.0"
|
version = "0.0.0"
|
||||||
authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>", "David Tolnay <dtolnay@gmail.com>"]
|
authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>", "David Tolnay <dtolnay@gmail.com>"]
|
||||||
|
edition = "2018"
|
||||||
publish = false
|
publish = false
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
unstable = ["serde/unstable", "compiletest_rs"]
|
unstable = ["serde/unstable"]
|
||||||
|
compiletest = ["compiletest_rs"]
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
fnv = "1.0"
|
fnv = "1.0"
|
||||||
rustc-serialize = "0.3.16"
|
rustc-serialize = "0.3.16"
|
||||||
serde = { path = "../serde", features = ["rc"] }
|
serde = { path = "../serde", features = ["rc", "derive"] }
|
||||||
serde_derive = { path = "../serde_derive", features = ["deserialize_in_place"] }
|
serde_derive = { path = "../serde_derive", features = ["deserialize_in_place"] }
|
||||||
serde_test = { path = "../serde_test" }
|
serde_test = { path = "../serde_test" }
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "serde_derive_tests_no_std"
|
name = "serde_derive_tests_no_std"
|
||||||
version = "0.0.0"
|
version = "0.0.0"
|
||||||
|
edition = "2018"
|
||||||
publish = false
|
publish = false
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
libc = { version = "0.2", default-features = false }
|
libc = { version = "0.2", default-features = false }
|
||||||
serde = { path = "../../serde", default-features = false }
|
serde = { path = "../../serde", default-features = false, features = ["derive"] }
|
||||||
serde_derive = { path = "../../serde_derive" }
|
|
||||||
|
|
||||||
[workspace]
|
[workspace]
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
#![feature(lang_items, start)]
|
#![feature(lang_items, start)]
|
||||||
#![no_std]
|
#![no_std]
|
||||||
|
|
||||||
extern crate libc;
|
|
||||||
|
|
||||||
#[start]
|
#[start]
|
||||||
fn start(_argc: isize, _argv: *const *const u8) -> isize {
|
fn start(_argc: isize, _argv: *const *const u8) -> isize {
|
||||||
0
|
0
|
||||||
@@ -21,8 +19,7 @@ fn panic(_info: &core::panic::PanicInfo) -> ! {
|
|||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#[macro_use]
|
use serde::{Serialize, Deserialize};
|
||||||
extern crate serde_derive;
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Serialize, Deserialize)]
|
||||||
struct Unit;
|
struct Unit;
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ impl<'de> Visitor<'de> for ByteBufVisitor {
|
|||||||
V: SeqAccess<'de>,
|
V: SeqAccess<'de>,
|
||||||
{
|
{
|
||||||
let mut values = Vec::new();
|
let mut values = Vec::new();
|
||||||
while let Some(value) = try!(visitor.next_element()) {
|
while let Some(value) = visitor.next_element()? {
|
||||||
values.push(value);
|
values.push(value);
|
||||||
}
|
}
|
||||||
Ok(values)
|
Ok(values)
|
||||||
|
|||||||
@@ -1,15 +1,20 @@
|
|||||||
#![cfg(feature = "unstable")]
|
#![cfg(feature = "compiletest")]
|
||||||
|
|
||||||
extern crate compiletest_rs as compiletest;
|
use compiletest_rs as compiletest;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn ui() {
|
fn ui() {
|
||||||
let config = compiletest::Config {
|
compiletest::run_tests(&compiletest::Config {
|
||||||
mode: compiletest::common::Mode::Ui,
|
mode: compiletest::common::Mode::Ui,
|
||||||
src_base: std::path::PathBuf::from("tests/ui"),
|
src_base: std::path::PathBuf::from("tests/ui"),
|
||||||
target_rustcflags: Some("-L deps/target/debug/deps".to_owned()),
|
target_rustcflags: Some(String::from(
|
||||||
|
"\
|
||||||
|
--edition=2018 \
|
||||||
|
-L deps/target/debug/deps \
|
||||||
|
-Z unstable-options \
|
||||||
|
--extern serde_derive \
|
||||||
|
",
|
||||||
|
)),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
});
|
||||||
|
|
||||||
compiletest::run_tests(&config);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,19 +1,13 @@
|
|||||||
#![cfg_attr(feature = "cargo-clippy", allow(renamed_and_removed_lints))]
|
#![allow(clippy::cast_lossless, clippy::trivially_copy_pass_by_ref)]
|
||||||
#![cfg_attr(feature = "cargo-clippy", allow(cast_lossless))]
|
|
||||||
|
|
||||||
#[macro_use]
|
use serde::de::{self, MapAccess, Unexpected, Visitor};
|
||||||
extern crate serde_derive;
|
use serde::{Deserialize, Deserializer, Serialize, Serializer};
|
||||||
|
|
||||||
extern crate serde;
|
|
||||||
use self::serde::de::{self, MapAccess, Unexpected, Visitor};
|
|
||||||
use self::serde::{Deserialize, Deserializer, Serialize, Serializer};
|
|
||||||
|
|
||||||
use std::collections::{BTreeMap, HashMap};
|
use std::collections::{BTreeMap, HashMap};
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
|
|
||||||
extern crate serde_test;
|
use serde_test::{
|
||||||
use self::serde_test::{
|
|
||||||
assert_de_tokens, assert_de_tokens_error, assert_ser_tokens, assert_ser_tokens_error,
|
assert_de_tokens, assert_de_tokens_error, assert_ser_tokens, assert_ser_tokens_error,
|
||||||
assert_tokens, Token,
|
assert_tokens, Token,
|
||||||
};
|
};
|
||||||
@@ -68,7 +62,7 @@ impl DeserializeWith for i32 {
|
|||||||
where
|
where
|
||||||
D: Deserializer<'de>,
|
D: Deserializer<'de>,
|
||||||
{
|
{
|
||||||
if try!(Deserialize::deserialize(de)) {
|
if Deserialize::deserialize(de)? {
|
||||||
Ok(123)
|
Ok(123)
|
||||||
} else {
|
} else {
|
||||||
Ok(2)
|
Ok(2)
|
||||||
@@ -522,6 +516,16 @@ struct RenameStructSerializeDeserialize {
|
|||||||
a2: i32,
|
a2: i32,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, PartialEq, Deserialize)]
|
||||||
|
#[serde(deny_unknown_fields)]
|
||||||
|
struct AliasStruct {
|
||||||
|
a1: i32,
|
||||||
|
#[serde(alias = "a3")]
|
||||||
|
a2: i32,
|
||||||
|
#[serde(alias = "a5", rename = "a6")]
|
||||||
|
a4: i32,
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_rename_struct() {
|
fn test_rename_struct() {
|
||||||
assert_tokens(
|
assert_tokens(
|
||||||
@@ -568,6 +572,59 @@ fn test_rename_struct() {
|
|||||||
Token::StructEnd,
|
Token::StructEnd,
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
assert_de_tokens(
|
||||||
|
&AliasStruct { a1: 1, a2: 2, a4: 3 },
|
||||||
|
&[
|
||||||
|
Token::Struct {
|
||||||
|
name: "AliasStruct",
|
||||||
|
len: 3,
|
||||||
|
},
|
||||||
|
Token::Str("a1"),
|
||||||
|
Token::I32(1),
|
||||||
|
Token::Str("a2"),
|
||||||
|
Token::I32(2),
|
||||||
|
Token::Str("a5"),
|
||||||
|
Token::I32(3),
|
||||||
|
Token::StructEnd,
|
||||||
|
],
|
||||||
|
);
|
||||||
|
|
||||||
|
assert_de_tokens(
|
||||||
|
&AliasStruct { a1: 1, a2: 2, a4: 3 },
|
||||||
|
&[
|
||||||
|
Token::Struct {
|
||||||
|
name: "AliasStruct",
|
||||||
|
len: 3,
|
||||||
|
},
|
||||||
|
Token::Str("a1"),
|
||||||
|
Token::I32(1),
|
||||||
|
Token::Str("a3"),
|
||||||
|
Token::I32(2),
|
||||||
|
Token::Str("a6"),
|
||||||
|
Token::I32(3),
|
||||||
|
Token::StructEnd,
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_unknown_field_rename_struct() {
|
||||||
|
assert_de_tokens_error::<AliasStruct>(
|
||||||
|
&[
|
||||||
|
Token::Struct {
|
||||||
|
name: "AliasStruct",
|
||||||
|
len: 3,
|
||||||
|
},
|
||||||
|
Token::Str("a1"),
|
||||||
|
Token::I32(1),
|
||||||
|
Token::Str("a3"),
|
||||||
|
Token::I32(2),
|
||||||
|
Token::Str("a4"),
|
||||||
|
Token::I32(3),
|
||||||
|
],
|
||||||
|
"unknown field `a4`, expected one of `a1`, `a2`, `a6`",
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
||||||
@@ -598,6 +655,19 @@ enum RenameEnumSerializeDeserialize<A> {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, PartialEq, Deserialize)]
|
||||||
|
#[serde(deny_unknown_fields)]
|
||||||
|
enum AliasEnum {
|
||||||
|
#[serde(rename = "sailor_moon", alias = "usagi_tsukino")]
|
||||||
|
SailorMoon {
|
||||||
|
a: i8,
|
||||||
|
#[serde(alias = "c")]
|
||||||
|
b: i8,
|
||||||
|
#[serde(alias = "e", rename = "f")]
|
||||||
|
d: i8,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_rename_enum() {
|
fn test_rename_enum() {
|
||||||
assert_tokens(
|
assert_tokens(
|
||||||
@@ -684,6 +754,81 @@ fn test_rename_enum() {
|
|||||||
Token::StructVariantEnd,
|
Token::StructVariantEnd,
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
assert_de_tokens(
|
||||||
|
&AliasEnum::SailorMoon {
|
||||||
|
a: 0,
|
||||||
|
b: 1,
|
||||||
|
d: 2,
|
||||||
|
},
|
||||||
|
&[
|
||||||
|
Token::StructVariant {
|
||||||
|
name: "AliasEnum",
|
||||||
|
variant: "sailor_moon",
|
||||||
|
len: 3,
|
||||||
|
},
|
||||||
|
Token::Str("a"),
|
||||||
|
Token::I8(0),
|
||||||
|
Token::Str("b"),
|
||||||
|
Token::I8(1),
|
||||||
|
Token::Str("e"),
|
||||||
|
Token::I8(2),
|
||||||
|
Token::StructVariantEnd,
|
||||||
|
],
|
||||||
|
);
|
||||||
|
|
||||||
|
assert_de_tokens(
|
||||||
|
&AliasEnum::SailorMoon {
|
||||||
|
a: 0,
|
||||||
|
b: 1,
|
||||||
|
d: 2,
|
||||||
|
},
|
||||||
|
&[
|
||||||
|
Token::StructVariant {
|
||||||
|
name: "AliasEnum",
|
||||||
|
variant: "usagi_tsukino",
|
||||||
|
len: 3,
|
||||||
|
},
|
||||||
|
Token::Str("a"),
|
||||||
|
Token::I8(0),
|
||||||
|
Token::Str("c"),
|
||||||
|
Token::I8(1),
|
||||||
|
Token::Str("f"),
|
||||||
|
Token::I8(2),
|
||||||
|
Token::StructVariantEnd,
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_unknown_field_rename_enum() {
|
||||||
|
assert_de_tokens_error::<AliasEnum>(
|
||||||
|
&[
|
||||||
|
Token::StructVariant {
|
||||||
|
name: "AliasEnum",
|
||||||
|
variant: "SailorMoon",
|
||||||
|
len: 3,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
"unknown variant `SailorMoon`, expected `sailor_moon`",
|
||||||
|
);
|
||||||
|
|
||||||
|
assert_de_tokens_error::<AliasEnum>(
|
||||||
|
&[
|
||||||
|
Token::StructVariant {
|
||||||
|
name: "AliasEnum",
|
||||||
|
variant: "usagi_tsukino",
|
||||||
|
len: 3,
|
||||||
|
},
|
||||||
|
Token::Str("a"),
|
||||||
|
Token::I8(0),
|
||||||
|
Token::Str("c"),
|
||||||
|
Token::I8(1),
|
||||||
|
Token::Str("d"),
|
||||||
|
Token::I8(2),
|
||||||
|
],
|
||||||
|
"unknown field `d`, expected one of `a`, `b`, `f`",
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Serialize)]
|
#[derive(Debug, PartialEq, Serialize)]
|
||||||
|
|||||||
@@ -1,10 +1,4 @@
|
|||||||
#[macro_use]
|
|
||||||
extern crate serde_derive;
|
|
||||||
|
|
||||||
extern crate serde;
|
|
||||||
use serde::{Deserialize, Deserializer};
|
use serde::{Deserialize, Deserializer};
|
||||||
|
|
||||||
extern crate serde_test;
|
|
||||||
use serde_test::{assert_de_tokens, assert_de_tokens_error, Token};
|
use serde_test::{assert_de_tokens, assert_de_tokens_error, Token};
|
||||||
|
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
|
|||||||
@@ -1,10 +1,6 @@
|
|||||||
#![cfg_attr(feature = "cargo-clippy", allow(renamed_and_removed_lints))]
|
#![allow(clippy::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]
|
|
||||||
extern crate serde_derive;
|
|
||||||
|
|
||||||
use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet};
|
use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet};
|
||||||
use std::default::Default;
|
use std::default::Default;
|
||||||
use std::ffi::{CStr, CString, OsString};
|
use std::ffi::{CStr, CString, OsString};
|
||||||
@@ -15,14 +11,9 @@ use std::rc::{Rc, Weak as RcWeak};
|
|||||||
use std::sync::{Arc, Weak as ArcWeak};
|
use std::sync::{Arc, Weak as ArcWeak};
|
||||||
use std::time::{Duration, UNIX_EPOCH};
|
use std::time::{Duration, UNIX_EPOCH};
|
||||||
|
|
||||||
extern crate serde;
|
use fnv::FnvHasher;
|
||||||
use serde::{Deserialize, Deserializer};
|
use serde::{Deserialize, Deserializer};
|
||||||
|
use serde_test::{assert_de_tokens, assert_de_tokens_error, Configure, Token};
|
||||||
extern crate fnv;
|
|
||||||
use self::fnv::FnvHasher;
|
|
||||||
|
|
||||||
extern crate serde_test;
|
|
||||||
use self::serde_test::{assert_de_tokens, assert_de_tokens_error, Configure, Token};
|
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
mod macros;
|
mod macros;
|
||||||
|
|||||||
@@ -4,13 +4,10 @@
|
|||||||
|
|
||||||
#![deny(warnings)]
|
#![deny(warnings)]
|
||||||
#![cfg_attr(feature = "unstable", feature(non_ascii_idents))]
|
#![cfg_attr(feature = "unstable", feature(non_ascii_idents))]
|
||||||
|
#![allow(clippy::trivially_copy_pass_by_ref)]
|
||||||
|
|
||||||
#[macro_use]
|
use serde::de::DeserializeOwned;
|
||||||
extern crate serde_derive;
|
use serde::{Deserialize, Deserializer, Serialize, Serializer};
|
||||||
|
|
||||||
extern crate serde;
|
|
||||||
use self::serde::de::{DeserializeOwned, Deserializer};
|
|
||||||
use self::serde::ser::{Serialize, Serializer};
|
|
||||||
|
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
@@ -384,6 +381,8 @@ fn test_gen() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
mod vis {
|
mod vis {
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
pub struct S;
|
pub struct S;
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Serialize, Deserialize)]
|
||||||
@@ -607,6 +606,8 @@ fn test_gen() {
|
|||||||
|
|
||||||
mod restricted {
|
mod restricted {
|
||||||
mod inner {
|
mod inner {
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Serialize, Deserialize)]
|
||||||
struct Restricted {
|
struct Restricted {
|
||||||
pub(super) a: usize,
|
pub(super) a: usize,
|
||||||
|
|||||||
@@ -1,7 +1,4 @@
|
|||||||
#[macro_use]
|
use serde::Deserialize;
|
||||||
extern crate serde_derive;
|
|
||||||
|
|
||||||
extern crate serde_test;
|
|
||||||
use serde_test::{assert_de_tokens, Token};
|
use serde_test::{assert_de_tokens, Token};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|||||||
@@ -1,16 +1,10 @@
|
|||||||
#![deny(trivial_numeric_casts)]
|
#![deny(trivial_numeric_casts)]
|
||||||
#![cfg_attr(feature = "cargo-clippy", allow(renamed_and_removed_lints))]
|
#![allow(clippy::redundant_field_names)]
|
||||||
#![cfg_attr(feature = "cargo-clippy", allow(redundant_field_names))]
|
|
||||||
|
|
||||||
#[macro_use]
|
|
||||||
extern crate serde_derive;
|
|
||||||
|
|
||||||
extern crate serde;
|
|
||||||
extern crate serde_test;
|
|
||||||
|
|
||||||
mod bytes;
|
mod bytes;
|
||||||
|
|
||||||
use self::serde_test::{
|
use serde::{Deserialize, Serialize};
|
||||||
|
use serde_test::{
|
||||||
assert_de_tokens, assert_de_tokens_error, assert_ser_tokens, assert_tokens, Token,
|
assert_de_tokens, assert_de_tokens_error, assert_ser_tokens, assert_tokens, Token,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -1376,6 +1370,60 @@ fn test_enum_in_internally_tagged_enum() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_internally_tagged_struct() {
|
||||||
|
#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
||||||
|
#[serde(tag = "type")]
|
||||||
|
pub struct Struct {
|
||||||
|
a: u8,
|
||||||
|
}
|
||||||
|
|
||||||
|
assert_tokens(
|
||||||
|
&Struct { a: 1 },
|
||||||
|
&[
|
||||||
|
Token::Struct {
|
||||||
|
name: "Struct",
|
||||||
|
len: 2,
|
||||||
|
},
|
||||||
|
Token::Str("type"),
|
||||||
|
Token::Str("Struct"),
|
||||||
|
Token::Str("a"),
|
||||||
|
Token::U8(1),
|
||||||
|
Token::StructEnd,
|
||||||
|
],
|
||||||
|
);
|
||||||
|
|
||||||
|
assert_de_tokens(
|
||||||
|
&Struct { a: 1 },
|
||||||
|
&[
|
||||||
|
Token::Struct {
|
||||||
|
name: "Struct",
|
||||||
|
len: 1,
|
||||||
|
},
|
||||||
|
Token::Str("a"),
|
||||||
|
Token::U8(1),
|
||||||
|
Token::StructEnd,
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_internally_tagged_braced_struct_with_zero_fields() {
|
||||||
|
#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
||||||
|
#[serde(tag = "type")]
|
||||||
|
struct S {}
|
||||||
|
|
||||||
|
assert_tokens(
|
||||||
|
&S {},
|
||||||
|
&[
|
||||||
|
Token::Struct { name: "S", len: 1 },
|
||||||
|
Token::Str("type"),
|
||||||
|
Token::Str("S"),
|
||||||
|
Token::StructEnd,
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_enum_in_untagged_enum() {
|
fn test_enum_in_untagged_enum() {
|
||||||
#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
#![cfg_attr(feature = "cargo-clippy", allow(renamed_and_removed_lints))]
|
#![allow(clippy::redundant_field_names)]
|
||||||
#![cfg_attr(feature = "cargo-clippy", allow(redundant_field_names))]
|
|
||||||
|
|
||||||
#[macro_use]
|
use serde::{Deserialize, Serialize};
|
||||||
extern crate serde_derive;
|
|
||||||
|
|
||||||
mod remote {
|
mod remote {
|
||||||
pub struct Unit;
|
pub struct Unit;
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
extern crate serde_test;
|
use serde_test::{assert_tokens, Configure, Token};
|
||||||
use self::serde_test::{assert_tokens, Configure, Token};
|
|
||||||
|
|
||||||
use std::net;
|
use std::net;
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,5 @@
|
|||||||
#![cfg_attr(feature = "unstable", feature(never_type))]
|
#![cfg_attr(feature = "unstable", feature(never_type))]
|
||||||
|
|
||||||
#[macro_use]
|
|
||||||
extern crate serde_derive;
|
|
||||||
|
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet};
|
use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet};
|
||||||
use std::ffi::CString;
|
use std::ffi::CString;
|
||||||
@@ -17,11 +14,9 @@ use std::time::{Duration, UNIX_EPOCH};
|
|||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
use std::str;
|
use std::str;
|
||||||
|
|
||||||
extern crate serde_test;
|
use fnv::FnvHasher;
|
||||||
use self::serde_test::{assert_ser_tokens, assert_ser_tokens_error, Configure, Token};
|
use serde::Serialize;
|
||||||
|
use serde_test::{assert_ser_tokens, assert_ser_tokens_error, Configure, Token};
|
||||||
extern crate fnv;
|
|
||||||
use self::fnv::FnvHasher;
|
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
mod macros;
|
mod macros;
|
||||||
|
|||||||
@@ -1,14 +1,5 @@
|
|||||||
#![deny(warnings)]
|
#![deny(warnings)]
|
||||||
|
|
||||||
#[cfg(feature = "unstable")]
|
|
||||||
#[macro_use]
|
|
||||||
extern crate serde_derive;
|
|
||||||
|
|
||||||
#[cfg(feature = "unstable")]
|
|
||||||
extern crate serde;
|
|
||||||
#[cfg(feature = "unstable")]
|
|
||||||
extern crate serde_test;
|
|
||||||
|
|
||||||
// This test target is convoluted with the actual #[test] in a separate file to
|
// This test target is convoluted with the actual #[test] in a separate file to
|
||||||
// get it so that the stable compiler does not need to parse the code of the
|
// get it so that the stable compiler does not need to parse the code of the
|
||||||
// test. If the test were written with #[cfg(feature = "unstable")] #[test]
|
// test. If the test were written with #[cfg(feature = "unstable")] #[test]
|
||||||
|
|||||||
@@ -1,7 +1,3 @@
|
|||||||
#[macro_use]
|
|
||||||
extern crate serde_derive;
|
|
||||||
|
|
||||||
extern crate serde;
|
|
||||||
use serde::de::{value, IntoDeserializer};
|
use serde::de::{value, IntoDeserializer};
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
#[macro_use]
|
use serde_derive::Deserialize;
|
||||||
extern crate serde_derive;
|
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
struct Test<'a> {
|
struct Test<'a> {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
error: failed to parse borrowed lifetimes: "zzz"
|
error: failed to parse borrowed lifetimes: "zzz"
|
||||||
--> $DIR/bad_lifetimes.rs:6:22
|
--> $DIR/bad_lifetimes.rs:5:22
|
||||||
|
|
|
|
||||||
6 | #[serde(borrow = "zzz")]
|
5 | #[serde(borrow = "zzz")]
|
||||||
| ^^^^^
|
| ^^^^^
|
||||||
|
|
||||||
error: aborting due to previous error
|
error: aborting due to previous error
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
#[macro_use]
|
use serde_derive::Deserialize;
|
||||||
extern crate serde_derive;
|
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
struct Test<'a> {
|
struct Test<'a> {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
error: duplicate borrowed lifetime `'a`
|
error: duplicate borrowed lifetime `'a`
|
||||||
--> $DIR/duplicate_lifetime.rs:6:22
|
--> $DIR/duplicate_lifetime.rs:5:22
|
||||||
|
|
|
|
||||||
6 | #[serde(borrow = "'a + 'a")]
|
5 | #[serde(borrow = "'a + 'a")]
|
||||||
| ^^^^^^^^^
|
| ^^^^^^^^^
|
||||||
|
|
||||||
error: aborting due to previous error
|
error: aborting due to previous error
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
#[macro_use]
|
use serde_derive::Deserialize;
|
||||||
extern crate serde_derive;
|
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
struct Str<'a>(&'a str);
|
struct Str<'a>(&'a str);
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
error: duplicate serde attribute `borrow`
|
error: duplicate serde attribute `borrow`
|
||||||
--> $DIR/duplicate_variant.rs:9:13
|
--> $DIR/duplicate_variant.rs:8:13
|
||||||
|
|
|
|
||||||
9 | #[serde(borrow)]
|
8 | #[serde(borrow)]
|
||||||
| ^^^^^^
|
| ^^^^^^
|
||||||
|
|
||||||
error: aborting due to previous error
|
error: aborting due to previous error
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
#[macro_use]
|
use serde_derive::Deserialize;
|
||||||
extern crate serde_derive;
|
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
struct Test<'a> {
|
struct Test<'a> {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
error: at least one lifetime must be borrowed
|
error: at least one lifetime must be borrowed
|
||||||
--> $DIR/empty_lifetimes.rs:6:22
|
--> $DIR/empty_lifetimes.rs:5:22
|
||||||
|
|
|
|
||||||
6 | #[serde(borrow = "")]
|
5 | #[serde(borrow = "")]
|
||||||
| ^^
|
| ^^
|
||||||
|
|
||||||
error: aborting due to previous error
|
error: aborting due to previous error
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
#[macro_use]
|
use serde_derive::Deserialize;
|
||||||
extern crate serde_derive;
|
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
struct Test {
|
struct Test {
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
error: field `s` has no lifetimes to borrow
|
error: field `s` has no lifetimes to borrow
|
||||||
--> $DIR/no_lifetimes.rs:6:5
|
--> $DIR/no_lifetimes.rs:5:5
|
||||||
|
|
|
|
||||||
6 | / #[serde(borrow)]
|
5 | / #[serde(borrow)]
|
||||||
7 | | s: String,
|
6 | | s: String,
|
||||||
| |_____________^
|
| |_____________^
|
||||||
|
|
||||||
error: aborting due to previous error
|
error: aborting due to previous error
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
#[macro_use]
|
use serde_derive::Deserialize;
|
||||||
extern crate serde_derive;
|
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
struct Str<'a>(&'a str);
|
struct Str<'a>(&'a str);
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
error: #[serde(borrow)] may only be used on newtype variants
|
error: #[serde(borrow)] may only be used on newtype variants
|
||||||
--> $DIR/struct_variant.rs:9:5
|
--> $DIR/struct_variant.rs:8:5
|
||||||
|
|
|
|
||||||
9 | / #[serde(borrow)]
|
8 | / #[serde(borrow)]
|
||||||
10 | | S { s: Str<'a> },
|
9 | | S { s: Str<'a> },
|
||||||
| |____________________^
|
| |____________________^
|
||||||
|
|
||||||
error: aborting due to previous error
|
error: aborting due to previous error
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
#[macro_use]
|
use serde_derive::Deserialize;
|
||||||
extern crate serde_derive;
|
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
struct Test<'a> {
|
struct Test<'a> {
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
error: field `s` does not have lifetime 'b
|
error: field `s` does not have lifetime 'b
|
||||||
--> $DIR/wrong_lifetime.rs:6:5
|
--> $DIR/wrong_lifetime.rs:5:5
|
||||||
|
|
|
|
||||||
6 | / #[serde(borrow = "'b")]
|
5 | / #[serde(borrow = "'b")]
|
||||||
7 | | s: &'a str,
|
6 | | s: &'a str,
|
||||||
| |______________^
|
| |______________^
|
||||||
|
|
||||||
error: aborting due to previous error
|
error: aborting due to previous error
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
#[macro_use]
|
use serde_derive::Serialize;
|
||||||
extern crate serde_derive;
|
|
||||||
|
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize)]
|
||||||
#[serde(tag = "conflict", content = "conflict")]
|
#[serde(tag = "conflict", content = "conflict")]
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
error: enum tags `conflict` for type and content conflict with each other
|
error: enum tags `conflict` for type and content conflict with each other
|
||||||
--> $DIR/adjacent-tag.rs:5:1
|
--> $DIR/adjacent-tag.rs:4:1
|
||||||
|
|
|
|
||||||
5 | / #[serde(tag = "conflict", content = "conflict")]
|
4 | / #[serde(tag = "conflict", content = "conflict")]
|
||||||
6 | | enum E {
|
5 | | enum E {
|
||||||
7 | | A,
|
6 | | A,
|
||||||
8 | | B,
|
7 | | B,
|
||||||
9 | | }
|
8 | | }
|
||||||
| |_^
|
| |_^
|
||||||
|
|
||||||
error: aborting due to previous error
|
error: aborting due to previous error
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
#[macro_use]
|
use serde_derive::Serialize;
|
||||||
extern crate serde_derive;
|
|
||||||
|
use std::collections::HashMap;
|
||||||
|
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize)]
|
||||||
struct Foo(#[serde(flatten)] HashMap<String, String>);
|
struct Foo(#[serde(flatten)] HashMap<String, String>);
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
error: #[serde(flatten)] cannot be used on newtype structs
|
error: #[serde(flatten)] cannot be used on newtype structs
|
||||||
--> $DIR/flatten-newtype-struct.rs:5:12
|
--> $DIR/flatten-newtype-struct.rs:6:12
|
||||||
|
|
|
|
||||||
5 | struct Foo(#[serde(flatten)] HashMap<String, String>);
|
6 | struct Foo(#[serde(flatten)] HashMap<String, String>);
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
error: aborting due to previous error
|
error: aborting due to previous error
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
#[macro_use]
|
use serde_derive::Deserialize;
|
||||||
extern crate serde_derive;
|
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
struct Foo {
|
struct Foo {
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
error: #[serde(flatten)] can not be combined with #[serde(skip_deserializing)]
|
error: #[serde(flatten)] can not be combined with #[serde(skip_deserializing)]
|
||||||
--> $DIR/flatten-skip-deserializing.rs:6:5
|
--> $DIR/flatten-skip-deserializing.rs:5:5
|
||||||
|
|
|
|
||||||
6 | / #[serde(flatten, skip_deserializing)]
|
5 | / #[serde(flatten, skip_deserializing)]
|
||||||
7 | | other: Other,
|
6 | | other: Other,
|
||||||
| |________________^
|
| |________________^
|
||||||
|
|
||||||
error: aborting due to previous error
|
error: aborting due to previous error
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
#[macro_use]
|
use serde_derive::Serialize;
|
||||||
extern crate serde_derive;
|
|
||||||
|
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize)]
|
||||||
struct Foo {
|
struct Foo {
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
error: #[serde(flatten)] can not be combined with #[serde(skip_serializing_if = "...")]
|
error: #[serde(flatten)] can not be combined with #[serde(skip_serializing_if = "...")]
|
||||||
--> $DIR/flatten-skip-serializing-if.rs:6:5
|
--> $DIR/flatten-skip-serializing-if.rs:5:5
|
||||||
|
|
|
|
||||||
6 | / #[serde(flatten, skip_serializing_if = "Option::is_none")]
|
5 | / #[serde(flatten, skip_serializing_if = "Option::is_none")]
|
||||||
7 | | other: Option<Other>,
|
6 | | other: Option<Other>,
|
||||||
| |________________________^
|
| |________________________^
|
||||||
|
|
||||||
error: aborting due to previous error
|
error: aborting due to previous error
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
#[macro_use]
|
use serde_derive::Serialize;
|
||||||
extern crate serde_derive;
|
|
||||||
|
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize)]
|
||||||
struct Foo {
|
struct Foo {
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
error: #[serde(flatten)] can not be combined with #[serde(skip_serializing)]
|
error: #[serde(flatten)] can not be combined with #[serde(skip_serializing)]
|
||||||
--> $DIR/flatten-skip-serializing.rs:6:5
|
--> $DIR/flatten-skip-serializing.rs:5:5
|
||||||
|
|
|
|
||||||
6 | / #[serde(flatten, skip_serializing)]
|
5 | / #[serde(flatten, skip_serializing)]
|
||||||
7 | | other: Other,
|
6 | | other: Other,
|
||||||
| |________________^
|
| |________________^
|
||||||
|
|
||||||
error: aborting due to previous error
|
error: aborting due to previous error
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
#[macro_use]
|
use serde_derive::Serialize;
|
||||||
extern crate serde_derive;
|
|
||||||
|
use std::collections::HashMap;
|
||||||
|
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize)]
|
||||||
struct Foo(u32, #[serde(flatten)] HashMap<String, String>);
|
struct Foo(u32, #[serde(flatten)] HashMap<String, String>);
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
error: #[serde(flatten)] cannot be used on tuple structs
|
error: #[serde(flatten)] cannot be used on tuple structs
|
||||||
--> $DIR/flatten-tuple-struct.rs:5:17
|
--> $DIR/flatten-tuple-struct.rs:6:17
|
||||||
|
|
|
|
||||||
5 | struct Foo(u32, #[serde(flatten)] HashMap<String, String>);
|
6 | struct Foo(u32, #[serde(flatten)] HashMap<String, String>);
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
error: aborting due to previous error
|
error: aborting due to previous error
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
use serde_derive::Serialize;
|
||||||
|
|
||||||
|
#[derive(Serialize)]
|
||||||
|
#[serde(tag = "conflict")]
|
||||||
|
enum E {
|
||||||
|
A {
|
||||||
|
#[serde(alias = "conflict")]
|
||||||
|
x: (),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
error: variant field name `conflict` conflicts with internal tag
|
||||||
|
--> $DIR/internal-tag-alias.rs:4:1
|
||||||
|
|
|
||||||
|
4 | / #[serde(tag = "conflict")]
|
||||||
|
5 | | enum E {
|
||||||
|
6 | | A {
|
||||||
|
7 | | #[serde(alias = "conflict")]
|
||||||
|
8 | | x: (),
|
||||||
|
9 | | },
|
||||||
|
10 | | }
|
||||||
|
| |_^
|
||||||
|
|
||||||
|
error: aborting due to previous error
|
||||||
|
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
#[macro_use]
|
use serde_derive::Serialize;
|
||||||
extern crate serde_derive;
|
|
||||||
|
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize)]
|
||||||
#[serde(tag = "conflict")]
|
#[serde(tag = "conflict")]
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
error: variant field name `conflict` conflicts with internal tag
|
error: variant field name `conflict` conflicts with internal tag
|
||||||
--> $DIR/internal-tag.rs:5:1
|
--> $DIR/internal-tag.rs:4:1
|
||||||
|
|
|
|
||||||
5 | / #[serde(tag = "conflict")]
|
4 | / #[serde(tag = "conflict")]
|
||||||
6 | | enum E {
|
5 | | enum E {
|
||||||
7 | | A {
|
6 | | A {
|
||||||
8 | | #[serde(rename = "conflict")]
|
7 | | #[serde(rename = "conflict")]
|
||||||
9 | | x: (),
|
8 | | x: (),
|
||||||
10 | | },
|
9 | | },
|
||||||
11 | | }
|
10 | | }
|
||||||
| |_^
|
| |_^
|
||||||
|
|
||||||
error: aborting due to previous error
|
error: aborting due to previous error
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
#[macro_use]
|
use serde_derive::Deserialize;
|
||||||
extern crate serde_derive;
|
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
enum E {
|
enum E {
|
||||||
S { f: u8 },
|
S { f: u8 },
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn main() {}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
error: #[serde(default)] can only be used on structs with named fields
|
error: #[serde(default)] can only be used on structs with named fields
|
||||||
--> $DIR/enum.rs:6:1
|
--> $DIR/enum.rs:5:1
|
||||||
|
|
|
|
||||||
6 | enum E {
|
5 | enum E {
|
||||||
| ^^^^
|
| ^^^^
|
||||||
|
|
||||||
error: aborting due to previous error
|
error: aborting due to previous error
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
#[macro_use]
|
use serde_derive::Deserialize;
|
||||||
extern crate serde_derive;
|
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
#[serde(default = "default_e")]
|
#[serde(default = "default_e")]
|
||||||
enum E {
|
enum E {
|
||||||
S { f: u8 },
|
S { f: u8 },
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn main() {}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
error: #[serde(default = "...")] can only be used on structs with named fields
|
error: #[serde(default = "...")] can only be used on structs with named fields
|
||||||
--> $DIR/enum_path.rs:6:1
|
--> $DIR/enum_path.rs:5:1
|
||||||
|
|
|
|
||||||
6 | enum E {
|
5 | enum E {
|
||||||
| ^^^^
|
| ^^^^
|
||||||
|
|
||||||
error: aborting due to previous error
|
error: aborting due to previous error
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
#[macro_use]
|
use serde_derive::Deserialize;
|
||||||
extern crate serde_derive;
|
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
error: #[serde(default)] can only be used on structs with named fields
|
error: #[serde(default)] can only be used on structs with named fields
|
||||||
--> $DIR/nameless_struct_fields.rs:6:9
|
--> $DIR/nameless_struct_fields.rs:5:9
|
||||||
|
|
|
|
||||||
6 | struct T(u8, u8);
|
5 | struct T(u8, u8);
|
||||||
| ^^^^^^^^
|
| ^^^^^^^^
|
||||||
|
|
||||||
error: aborting due to previous error
|
error: aborting due to previous error
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
#[macro_use]
|
use serde_derive::Deserialize;
|
||||||
extern crate serde_derive;
|
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
#[serde(default = "default_t")]
|
#[serde(default = "default_t")]
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
error: #[serde(default = "...")] can only be used on structs with named fields
|
error: #[serde(default = "...")] can only be used on structs with named fields
|
||||||
--> $DIR/nameless_struct_fields_path.rs:6:9
|
--> $DIR/nameless_struct_fields_path.rs:5:9
|
||||||
|
|
|
|
||||||
6 | struct T(u8, u8);
|
5 | struct T(u8, u8);
|
||||||
| ^^^^^^^^
|
| ^^^^^^^^
|
||||||
|
|
||||||
error: aborting due to previous error
|
error: aborting due to previous error
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
#[macro_use]
|
use serde_derive::Serialize;
|
||||||
extern crate serde_derive;
|
|
||||||
|
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize)]
|
||||||
struct S {
|
struct S {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
error: unknown serde field attribute `serialize`
|
error: unknown serde field attribute `serialize`
|
||||||
--> $DIR/rename-and-ser.rs:6:27
|
--> $DIR/rename-and-ser.rs:5:27
|
||||||
|
|
|
|
||||||
6 | #[serde(rename = "x", serialize = "y")]
|
5 | #[serde(rename = "x", serialize = "y")]
|
||||||
| ^^^^^^^^^
|
| ^^^^^^^^^
|
||||||
|
|
||||||
error: aborting due to previous error
|
error: aborting due to previous error
|
||||||
|
|||||||
@@ -1,11 +0,0 @@
|
|||||||
#[macro_use]
|
|
||||||
extern crate serde_derive;
|
|
||||||
|
|
||||||
#[derive(Serialize)]
|
|
||||||
struct S {
|
|
||||||
#[serde(rename = "x")]
|
|
||||||
#[serde(rename(deserialize = "y"))]
|
|
||||||
x: (),
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {}
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
error: duplicate serde attribute `rename`
|
|
||||||
--> $DIR/rename-rename-de.rs:7:13
|
|
||||||
|
|
|
||||||
7 | #[serde(rename(deserialize = "y"))]
|
|
||||||
| ^^^^^^
|
|
||||||
|
|
||||||
error: aborting due to previous error
|
|
||||||
|
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
#[macro_use]
|
use serde_derive::Serialize;
|
||||||
extern crate serde_derive;
|
|
||||||
|
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize)]
|
||||||
struct S {
|
struct S {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
error: duplicate serde attribute `rename`
|
error: duplicate serde attribute `rename`
|
||||||
--> $DIR/rename-ser-rename-ser.rs:6:38
|
--> $DIR/rename-ser-rename-ser.rs:5:38
|
||||||
|
|
|
|
||||||
6 | #[serde(rename(serialize = "x"), rename(serialize = "y"))]
|
5 | #[serde(rename(serialize = "x"), rename(serialize = "y"))]
|
||||||
| ^^^^^^
|
| ^^^^^^
|
||||||
|
|
||||||
error: aborting due to previous error
|
error: aborting due to previous error
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
#[macro_use]
|
use serde_derive::Serialize;
|
||||||
extern crate serde_derive;
|
|
||||||
|
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize)]
|
||||||
struct S {
|
struct S {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
error: duplicate serde attribute `rename`
|
error: duplicate serde attribute `rename`
|
||||||
--> $DIR/rename-ser-rename.rs:7:13
|
--> $DIR/rename-ser-rename.rs:6:13
|
||||||
|
|
|
|
||||||
7 | #[serde(rename = "y")]
|
6 | #[serde(rename = "y")]
|
||||||
| ^^^^^^
|
| ^^^^^^
|
||||||
|
|
||||||
error: aborting due to previous error
|
error: aborting due to previous error
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
#[macro_use]
|
use serde_derive::Serialize;
|
||||||
extern crate serde_derive;
|
|
||||||
|
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize)]
|
||||||
struct S {
|
struct S {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
error: duplicate serde attribute `rename`
|
error: duplicate serde attribute `rename`
|
||||||
--> $DIR/rename-ser-ser.rs:6:37
|
--> $DIR/rename-ser-ser.rs:5:37
|
||||||
|
|
|
|
||||||
6 | #[serde(rename(serialize = "x", serialize = "y"))]
|
5 | #[serde(rename(serialize = "x", serialize = "y"))]
|
||||||
| ^^^^^^^^^
|
| ^^^^^^^^^
|
||||||
|
|
||||||
error: aborting due to previous error
|
error: aborting due to previous error
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
#[macro_use]
|
use serde_derive::Serialize;
|
||||||
extern crate serde_derive;
|
|
||||||
|
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize)]
|
||||||
struct S {
|
struct S {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
error: duplicate serde attribute `rename`
|
error: duplicate serde attribute `rename`
|
||||||
--> $DIR/two-rename-ser.rs:7:13
|
--> $DIR/two-rename-ser.rs:6:13
|
||||||
|
|
|
|
||||||
7 | #[serde(rename(serialize = "y"))]
|
6 | #[serde(rename(serialize = "y"))]
|
||||||
| ^^^^^^
|
| ^^^^^^
|
||||||
|
|
||||||
error: aborting due to previous error
|
error: aborting due to previous error
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
#[macro_use]
|
use serde_derive::Serialize;
|
||||||
extern crate serde_derive;
|
|
||||||
|
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize)]
|
||||||
struct S {
|
struct S {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
error: duplicate serde attribute `serialize_with`
|
error: duplicate serde attribute `serialize_with`
|
||||||
--> $DIR/with-and-serialize-with.rs:6:25
|
--> $DIR/with-and-serialize-with.rs:5:25
|
||||||
|
|
|
|
||||||
6 | #[serde(with = "w", serialize_with = "s")]
|
5 | #[serde(with = "w", serialize_with = "s")]
|
||||||
| ^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^
|
||||||
|
|
||||||
error: aborting due to previous error
|
error: aborting due to previous error
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
#[macro_use]
|
use serde_derive::Serialize;
|
||||||
extern crate serde_derive;
|
|
||||||
|
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize)]
|
||||||
#[serde(content = "c")]
|
#[serde(content = "c")]
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
error: #[serde(tag = "...", content = "...")] must be used together
|
error: #[serde(tag = "...", content = "...")] must be used together
|
||||||
--> $DIR/content-no-tag.rs:5:9
|
--> $DIR/content-no-tag.rs:4:9
|
||||||
|
|
|
|
||||||
5 | #[serde(content = "c")]
|
4 | #[serde(content = "c")]
|
||||||
| ^^^^^^^
|
| ^^^^^^^
|
||||||
|
|
||||||
error: aborting due to previous error
|
error: aborting due to previous error
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
#[macro_use]
|
use serde_derive::Serialize;
|
||||||
extern crate serde_derive;
|
|
||||||
|
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize)]
|
||||||
#[serde(tag = "type")]
|
#[serde(tag = "type")]
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
error: #[serde(tag = "...")] cannot be used with tuple variants
|
error: #[serde(tag = "...")] cannot be used with tuple variants
|
||||||
--> $DIR/internal-tuple-variant.rs:7:5
|
--> $DIR/internal-tuple-variant.rs:6:5
|
||||||
|
|
|
|
||||||
7 | Tuple(u8, u8),
|
6 | Tuple(u8, u8),
|
||||||
| ^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^
|
||||||
|
|
||||||
error: aborting due to previous error
|
error: aborting due to previous error
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user