mirror of
https://github.com/pezkuwichain/serde.git
synced 2026-04-28 14:57:56 +00:00
Compare commits
54 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 03da66c805 | |||
| f75426f47e | |||
| 662fc3861c | |||
| 28c10020b9 | |||
| 89c8d85de9 | |||
| 6502838f27 | |||
| c93a0f335a | |||
| 8264e002a7 | |||
| 117ef22142 | |||
| 3fb5e71c33 | |||
| 296db177e2 | |||
| e4a4389177 | |||
| 7aa0453c3b | |||
| 09b78b24e9 | |||
| a622b8a74a | |||
| 399ef081ec | |||
| 3686277e14 | |||
| 807bd20a64 | |||
| ed9a140348 | |||
| 2de7c2bea2 | |||
| e6a4a3772e | |||
| 0fca04e1a6 | |||
| 92bfc8d3af | |||
| fa0312ac45 | |||
| 1920b694aa | |||
| 3bfd41d624 | |||
| 290449f19b | |||
| 3a1f387e69 | |||
| 541603ac94 | |||
| 0666fbfa20 | |||
| ea071ae1d4 | |||
| 992a01bad2 | |||
| d640b5624f | |||
| 48479e4bae | |||
| dfaf48bc09 | |||
| 4cf1fec575 | |||
| ee7d77defa | |||
| d0dfc4577e | |||
| bbbd1d24c9 | |||
| fb3a9e0d7c | |||
| 5ffebeb6ef | |||
| 75db73066b | |||
| 2796833c82 | |||
| 95730dc7f7 | |||
| 795261919f | |||
| 3783a30ae7 | |||
| b61ec84886 | |||
| 780a461d92 | |||
| c604bdbfe4 | |||
| 9fef892f6d | |||
| b1c7db47b8 | |||
| e76e87a430 | |||
| 51799dd654 | |||
| 732ac49321 |
@@ -128,6 +128,16 @@ jobs:
|
|||||||
- uses: dtolnay/rust-toolchain@1.36.0
|
- uses: dtolnay/rust-toolchain@1.36.0
|
||||||
- run: cd serde && cargo build --no-default-features --features alloc
|
- run: cd serde && cargo build --no-default-features --features alloc
|
||||||
|
|
||||||
|
minimal:
|
||||||
|
name: Minimal versions
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
timeout-minutes: 45
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
- uses: dtolnay/rust-toolchain@nightly
|
||||||
|
- run: cargo generate-lockfile -Z minimal-versions
|
||||||
|
- run: cargo check --locked --workspace
|
||||||
|
|
||||||
clippy:
|
clippy:
|
||||||
name: Clippy
|
name: Clippy
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ serde_json = "1.0"
|
|||||||
<p></p>
|
<p></p>
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
use serde::{Serialize, Deserialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug)]
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
struct Point {
|
struct Point {
|
||||||
|
|||||||
+1
-1
@@ -16,7 +16,7 @@ You may be looking for:
|
|||||||
## Serde in action
|
## Serde in action
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
use serde::{Serialize, Deserialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug)]
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
struct Point {
|
struct Point {
|
||||||
|
|||||||
+3
-3
@@ -1,9 +1,9 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "serde"
|
name = "serde"
|
||||||
version = "1.0.165" # remember to update html_root_url and serde_derive dependency
|
version = "1.0.171" # remember to update html_root_url and serde_derive dependency
|
||||||
authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>", "David Tolnay <dtolnay@gmail.com>"]
|
authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>", "David Tolnay <dtolnay@gmail.com>"]
|
||||||
build = "build.rs"
|
build = "build.rs"
|
||||||
categories = ["encoding", "no-std"]
|
categories = ["encoding", "no-std", "no-std::no-alloc"]
|
||||||
description = "A generic serialization/deserialization framework"
|
description = "A generic serialization/deserialization framework"
|
||||||
documentation = "https://docs.rs/serde"
|
documentation = "https://docs.rs/serde"
|
||||||
homepage = "https://serde.rs"
|
homepage = "https://serde.rs"
|
||||||
@@ -15,7 +15,7 @@ repository = "https://github.com/serde-rs/serde"
|
|||||||
rust-version = "1.19"
|
rust-version = "1.19"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
serde_derive = { version = "=1.0.165", optional = true, path = "../serde_derive" }
|
serde_derive = { version = "=1.0.171", 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" }
|
||||||
|
|||||||
@@ -10,13 +10,12 @@ use de::{
|
|||||||
/// 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.
|
||||||
///
|
///
|
||||||
/// ```edition2018
|
/// ```edition2021
|
||||||
/// use std::fmt;
|
|
||||||
/// use std::marker::PhantomData;
|
|
||||||
///
|
|
||||||
/// use serde::de::{
|
/// use serde::de::{
|
||||||
/// self, Deserialize, DeserializeSeed, Deserializer, IgnoredAny, SeqAccess, Visitor,
|
/// self, Deserialize, DeserializeSeed, Deserializer, IgnoredAny, SeqAccess, Visitor,
|
||||||
/// };
|
/// };
|
||||||
|
/// use std::fmt;
|
||||||
|
/// use std::marker::PhantomData;
|
||||||
///
|
///
|
||||||
/// /// A seed that can be used to deserialize only the `n`th element of a sequence
|
/// /// A seed that can be used to deserialize only the `n`th element of a sequence
|
||||||
/// /// while efficiently discarding elements of any type before or after index `n`.
|
/// /// while efficiently discarding elements of any type before or after index `n`.
|
||||||
@@ -108,7 +107,7 @@ use de::{
|
|||||||
/// # Ok(())
|
/// # Ok(())
|
||||||
/// # }
|
/// # }
|
||||||
/// ```
|
/// ```
|
||||||
#[derive(Copy, Clone, Debug, Default)]
|
#[derive(Copy, Clone, Debug, Default, PartialEq)]
|
||||||
pub struct IgnoredAny;
|
pub struct IgnoredAny;
|
||||||
|
|
||||||
impl<'de> Visitor<'de> for IgnoredAny {
|
impl<'de> Visitor<'de> for IgnoredAny {
|
||||||
|
|||||||
+290
-13
@@ -681,8 +681,8 @@ impl<'de> Visitor<'de> for CStringVisitor {
|
|||||||
where
|
where
|
||||||
A: SeqAccess<'de>,
|
A: SeqAccess<'de>,
|
||||||
{
|
{
|
||||||
let len = size_hint::cautious(seq.size_hint());
|
let capacity = size_hint::cautious::<u8>(seq.size_hint());
|
||||||
let mut values = Vec::with_capacity(len);
|
let mut values = Vec::<u8>::with_capacity(capacity);
|
||||||
|
|
||||||
while let Some(value) = try!(seq.next_element()) {
|
while let Some(value) = try!(seq.next_element()) {
|
||||||
values.push(value);
|
values.push(value);
|
||||||
@@ -936,7 +936,7 @@ macro_rules! seq_impl {
|
|||||||
A: SeqAccess<'de>,
|
A: SeqAccess<'de>,
|
||||||
{
|
{
|
||||||
$clear(&mut self.0);
|
$clear(&mut self.0);
|
||||||
$reserve(&mut self.0, size_hint::cautious($access.size_hint()));
|
$reserve(&mut self.0, size_hint::cautious::<T>($access.size_hint()));
|
||||||
|
|
||||||
// FIXME: try to overwrite old values here? (Vec, VecDeque, LinkedList)
|
// FIXME: try to overwrite old values here? (Vec, VecDeque, LinkedList)
|
||||||
while let Some(value) = try!($access.next_element()) {
|
while let Some(value) = try!($access.next_element()) {
|
||||||
@@ -962,7 +962,7 @@ seq_impl!(
|
|||||||
BinaryHeap<T: Ord>,
|
BinaryHeap<T: Ord>,
|
||||||
seq,
|
seq,
|
||||||
BinaryHeap::clear,
|
BinaryHeap::clear,
|
||||||
BinaryHeap::with_capacity(size_hint::cautious(seq.size_hint())),
|
BinaryHeap::with_capacity(size_hint::cautious::<T>(seq.size_hint())),
|
||||||
BinaryHeap::reserve,
|
BinaryHeap::reserve,
|
||||||
BinaryHeap::push
|
BinaryHeap::push
|
||||||
);
|
);
|
||||||
@@ -992,7 +992,7 @@ seq_impl!(
|
|||||||
HashSet<T: Eq + Hash, S: BuildHasher + Default>,
|
HashSet<T: Eq + Hash, S: BuildHasher + Default>,
|
||||||
seq,
|
seq,
|
||||||
HashSet::clear,
|
HashSet::clear,
|
||||||
HashSet::with_capacity_and_hasher(size_hint::cautious(seq.size_hint()), S::default()),
|
HashSet::with_capacity_and_hasher(size_hint::cautious::<T>(seq.size_hint()), S::default()),
|
||||||
HashSet::reserve,
|
HashSet::reserve,
|
||||||
HashSet::insert
|
HashSet::insert
|
||||||
);
|
);
|
||||||
@@ -1002,7 +1002,7 @@ seq_impl!(
|
|||||||
VecDeque<T>,
|
VecDeque<T>,
|
||||||
seq,
|
seq,
|
||||||
VecDeque::clear,
|
VecDeque::clear,
|
||||||
VecDeque::with_capacity(size_hint::cautious(seq.size_hint())),
|
VecDeque::with_capacity(size_hint::cautious::<T>(seq.size_hint())),
|
||||||
VecDeque::reserve,
|
VecDeque::reserve,
|
||||||
VecDeque::push_back
|
VecDeque::push_back
|
||||||
);
|
);
|
||||||
@@ -1036,7 +1036,8 @@ where
|
|||||||
where
|
where
|
||||||
A: SeqAccess<'de>,
|
A: SeqAccess<'de>,
|
||||||
{
|
{
|
||||||
let mut values = Vec::with_capacity(size_hint::cautious(seq.size_hint()));
|
let capacity = size_hint::cautious::<T>(seq.size_hint());
|
||||||
|
let mut values = Vec::<T>::with_capacity(capacity);
|
||||||
|
|
||||||
while let Some(value) = try!(seq.next_element()) {
|
while let Some(value) = try!(seq.next_element()) {
|
||||||
values.push(value);
|
values.push(value);
|
||||||
@@ -1072,7 +1073,7 @@ where
|
|||||||
where
|
where
|
||||||
A: SeqAccess<'de>,
|
A: SeqAccess<'de>,
|
||||||
{
|
{
|
||||||
let hint = size_hint::cautious(seq.size_hint());
|
let hint = size_hint::cautious::<T>(seq.size_hint());
|
||||||
if let Some(additional) = hint.checked_sub(self.0.len()) {
|
if let Some(additional) = hint.checked_sub(self.0.len()) {
|
||||||
self.0.reserve(additional);
|
self.0.reserve(additional);
|
||||||
}
|
}
|
||||||
@@ -1416,7 +1417,7 @@ map_impl!(BTreeMap<K: Ord, V>, map, BTreeMap::new());
|
|||||||
map_impl!(
|
map_impl!(
|
||||||
HashMap<K: Eq + Hash, V, S: BuildHasher + Default>,
|
HashMap<K: Eq + Hash, V, S: BuildHasher + Default>,
|
||||||
map,
|
map,
|
||||||
HashMap::with_capacity_and_hasher(size_hint::cautious(map.size_hint()), S::default())
|
HashMap::with_capacity_and_hasher(size_hint::cautious::<(K, V)>(map.size_hint()), S::default())
|
||||||
);
|
);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
@@ -1450,7 +1451,7 @@ macro_rules! variant_identifier {
|
|||||||
$($variant),*
|
$($variant),*
|
||||||
}
|
}
|
||||||
|
|
||||||
static $variants_name: &'static [&'static str] = &[$(stringify!($variant)),*];
|
static $variants_name: &[&str] = &[$(stringify!($variant)),*];
|
||||||
|
|
||||||
impl<'de> Deserialize<'de> for $name_kind {
|
impl<'de> Deserialize<'de> for $name_kind {
|
||||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||||
@@ -2256,9 +2257,9 @@ impl<'de> Deserialize<'de> for SystemTime {
|
|||||||
//
|
//
|
||||||
// #[derive(Deserialize)]
|
// #[derive(Deserialize)]
|
||||||
// #[serde(deny_unknown_fields)]
|
// #[serde(deny_unknown_fields)]
|
||||||
// struct Range {
|
// struct Range<Idx> {
|
||||||
// start: u64,
|
// start: Idx,
|
||||||
// end: u32,
|
// end: Idx,
|
||||||
// }
|
// }
|
||||||
impl<'de, Idx> Deserialize<'de> for Range<Idx>
|
impl<'de, Idx> Deserialize<'de> for Range<Idx>
|
||||||
where
|
where
|
||||||
@@ -2432,6 +2433,282 @@ mod range {
|
|||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
// Similar to:
|
||||||
|
//
|
||||||
|
// #[derive(Deserialize)]
|
||||||
|
// #[serde(deny_unknown_fields)]
|
||||||
|
// struct RangeFrom<Idx> {
|
||||||
|
// start: Idx,
|
||||||
|
// }
|
||||||
|
impl<'de, Idx> Deserialize<'de> for RangeFrom<Idx>
|
||||||
|
where
|
||||||
|
Idx: Deserialize<'de>,
|
||||||
|
{
|
||||||
|
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||||
|
where
|
||||||
|
D: Deserializer<'de>,
|
||||||
|
{
|
||||||
|
let start = try!(deserializer.deserialize_struct(
|
||||||
|
"RangeFrom",
|
||||||
|
range_from::FIELDS,
|
||||||
|
range_from::RangeFromVisitor {
|
||||||
|
expecting: "struct RangeFrom",
|
||||||
|
phantom: PhantomData,
|
||||||
|
},
|
||||||
|
));
|
||||||
|
Ok(start..)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mod range_from {
|
||||||
|
use lib::*;
|
||||||
|
|
||||||
|
use de::{Deserialize, Deserializer, Error, MapAccess, SeqAccess, Visitor};
|
||||||
|
|
||||||
|
pub const FIELDS: &[&str] = &["end"];
|
||||||
|
|
||||||
|
// If this were outside of the serde crate, it would just use:
|
||||||
|
//
|
||||||
|
// #[derive(Deserialize)]
|
||||||
|
// #[serde(field_identifier, rename_all = "lowercase")]
|
||||||
|
enum Field {
|
||||||
|
End,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'de> Deserialize<'de> for Field {
|
||||||
|
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||||
|
where
|
||||||
|
D: Deserializer<'de>,
|
||||||
|
{
|
||||||
|
struct FieldVisitor;
|
||||||
|
|
||||||
|
impl<'de> Visitor<'de> for FieldVisitor {
|
||||||
|
type Value = Field;
|
||||||
|
|
||||||
|
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||||
|
formatter.write_str("`end`")
|
||||||
|
}
|
||||||
|
|
||||||
|
fn visit_str<E>(self, value: &str) -> Result<Self::Value, E>
|
||||||
|
where
|
||||||
|
E: Error,
|
||||||
|
{
|
||||||
|
match value {
|
||||||
|
"end" => Ok(Field::End),
|
||||||
|
_ => Err(Error::unknown_field(value, FIELDS)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn visit_bytes<E>(self, value: &[u8]) -> Result<Self::Value, E>
|
||||||
|
where
|
||||||
|
E: Error,
|
||||||
|
{
|
||||||
|
match value {
|
||||||
|
b"end" => Ok(Field::End),
|
||||||
|
_ => {
|
||||||
|
let value = ::__private::from_utf8_lossy(value);
|
||||||
|
Err(Error::unknown_field(&*value, FIELDS))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
deserializer.deserialize_identifier(FieldVisitor)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct RangeFromVisitor<Idx> {
|
||||||
|
pub expecting: &'static str,
|
||||||
|
pub phantom: PhantomData<Idx>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'de, Idx> Visitor<'de> for RangeFromVisitor<Idx>
|
||||||
|
where
|
||||||
|
Idx: Deserialize<'de>,
|
||||||
|
{
|
||||||
|
type Value = Idx;
|
||||||
|
|
||||||
|
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||||
|
formatter.write_str(self.expecting)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn visit_seq<A>(self, mut seq: A) -> Result<Self::Value, A::Error>
|
||||||
|
where
|
||||||
|
A: SeqAccess<'de>,
|
||||||
|
{
|
||||||
|
let end: Idx = match try!(seq.next_element()) {
|
||||||
|
Some(value) => value,
|
||||||
|
None => {
|
||||||
|
return Err(Error::invalid_length(0, &self));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
Ok(end)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error>
|
||||||
|
where
|
||||||
|
A: MapAccess<'de>,
|
||||||
|
{
|
||||||
|
let mut end: Option<Idx> = None;
|
||||||
|
while let Some(key) = try!(map.next_key()) {
|
||||||
|
match key {
|
||||||
|
Field::End => {
|
||||||
|
if end.is_some() {
|
||||||
|
return Err(<A::Error as Error>::duplicate_field("end"));
|
||||||
|
}
|
||||||
|
end = Some(try!(map.next_value()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let end = match end {
|
||||||
|
Some(end) => end,
|
||||||
|
None => return Err(<A::Error as Error>::missing_field("end")),
|
||||||
|
};
|
||||||
|
Ok(end)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
// Similar to:
|
||||||
|
//
|
||||||
|
// #[derive(Deserialize)]
|
||||||
|
// #[serde(deny_unknown_fields)]
|
||||||
|
// struct RangeTo<Idx> {
|
||||||
|
// start: Idx,
|
||||||
|
// }
|
||||||
|
impl<'de, Idx> Deserialize<'de> for RangeTo<Idx>
|
||||||
|
where
|
||||||
|
Idx: Deserialize<'de>,
|
||||||
|
{
|
||||||
|
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||||
|
where
|
||||||
|
D: Deserializer<'de>,
|
||||||
|
{
|
||||||
|
let end = try!(deserializer.deserialize_struct(
|
||||||
|
"RangeTo",
|
||||||
|
range_to::FIELDS,
|
||||||
|
range_to::RangeToVisitor {
|
||||||
|
expecting: "struct RangeTo",
|
||||||
|
phantom: PhantomData,
|
||||||
|
},
|
||||||
|
));
|
||||||
|
Ok(..end)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mod range_to {
|
||||||
|
use lib::*;
|
||||||
|
|
||||||
|
use de::{Deserialize, Deserializer, Error, MapAccess, SeqAccess, Visitor};
|
||||||
|
|
||||||
|
pub const FIELDS: &[&str] = &["start"];
|
||||||
|
|
||||||
|
// If this were outside of the serde crate, it would just use:
|
||||||
|
//
|
||||||
|
// #[derive(Deserialize)]
|
||||||
|
// #[serde(field_identifier, rename_all = "lowercase")]
|
||||||
|
enum Field {
|
||||||
|
Start,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'de> Deserialize<'de> for Field {
|
||||||
|
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||||
|
where
|
||||||
|
D: Deserializer<'de>,
|
||||||
|
{
|
||||||
|
struct FieldVisitor;
|
||||||
|
|
||||||
|
impl<'de> Visitor<'de> for FieldVisitor {
|
||||||
|
type Value = Field;
|
||||||
|
|
||||||
|
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||||
|
formatter.write_str("`start`")
|
||||||
|
}
|
||||||
|
|
||||||
|
fn visit_str<E>(self, value: &str) -> Result<Self::Value, E>
|
||||||
|
where
|
||||||
|
E: Error,
|
||||||
|
{
|
||||||
|
match value {
|
||||||
|
"start" => Ok(Field::Start),
|
||||||
|
_ => Err(Error::unknown_field(value, FIELDS)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn visit_bytes<E>(self, value: &[u8]) -> Result<Self::Value, E>
|
||||||
|
where
|
||||||
|
E: Error,
|
||||||
|
{
|
||||||
|
match value {
|
||||||
|
b"start" => Ok(Field::Start),
|
||||||
|
_ => {
|
||||||
|
let value = ::__private::from_utf8_lossy(value);
|
||||||
|
Err(Error::unknown_field(&*value, FIELDS))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
deserializer.deserialize_identifier(FieldVisitor)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct RangeToVisitor<Idx> {
|
||||||
|
pub expecting: &'static str,
|
||||||
|
pub phantom: PhantomData<Idx>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'de, Idx> Visitor<'de> for RangeToVisitor<Idx>
|
||||||
|
where
|
||||||
|
Idx: Deserialize<'de>,
|
||||||
|
{
|
||||||
|
type Value = Idx;
|
||||||
|
|
||||||
|
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||||
|
formatter.write_str(self.expecting)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn visit_seq<A>(self, mut seq: A) -> Result<Self::Value, A::Error>
|
||||||
|
where
|
||||||
|
A: SeqAccess<'de>,
|
||||||
|
{
|
||||||
|
let start: Idx = match try!(seq.next_element()) {
|
||||||
|
Some(value) => value,
|
||||||
|
None => {
|
||||||
|
return Err(Error::invalid_length(0, &self));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
Ok(start)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error>
|
||||||
|
where
|
||||||
|
A: MapAccess<'de>,
|
||||||
|
{
|
||||||
|
let mut start: Option<Idx> = None;
|
||||||
|
while let Some(key) = try!(map.next_key()) {
|
||||||
|
match key {
|
||||||
|
Field::Start => {
|
||||||
|
if start.is_some() {
|
||||||
|
return Err(<A::Error as Error>::duplicate_field("start"));
|
||||||
|
}
|
||||||
|
start = Some(try!(map.next_value()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let start = match start {
|
||||||
|
Some(start) => start,
|
||||||
|
None => return Err(<A::Error as Error>::missing_field("start")),
|
||||||
|
};
|
||||||
|
Ok(start)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#[cfg(any(not(no_ops_bound), all(feature = "std", not(no_collections_bound))))]
|
#[cfg(any(not(no_ops_bound), all(feature = "std", not(no_collections_bound))))]
|
||||||
impl<'de, T> Deserialize<'de> for Bound<T>
|
impl<'de, T> Deserialize<'de> for Bound<T>
|
||||||
where
|
where
|
||||||
|
|||||||
+27
-31
@@ -162,7 +162,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.
|
||||||
///
|
///
|
||||||
/// ```edition2018
|
/// ```edition2021
|
||||||
/// # use std::str::FromStr;
|
/// # use std::str::FromStr;
|
||||||
/// #
|
/// #
|
||||||
/// # struct IpAddr;
|
/// # struct IpAddr;
|
||||||
@@ -307,7 +307,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.
|
||||||
///
|
///
|
||||||
/// ```edition2018
|
/// ```edition2021
|
||||||
/// # use std::fmt;
|
/// # use std::fmt;
|
||||||
/// #
|
/// #
|
||||||
/// # use serde::de::{self, Unexpected, Visitor};
|
/// # use serde::de::{self, Unexpected, Visitor};
|
||||||
@@ -432,10 +432,9 @@ 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.
|
||||||
///
|
///
|
||||||
/// ```edition2018
|
/// ```edition2021
|
||||||
/// # use std::fmt;
|
|
||||||
/// #
|
|
||||||
/// # use serde::de::{self, Unexpected, Visitor};
|
/// # use serde::de::{self, Unexpected, Visitor};
|
||||||
|
/// # use std::fmt;
|
||||||
/// #
|
/// #
|
||||||
/// # struct Example;
|
/// # struct Example;
|
||||||
/// #
|
/// #
|
||||||
@@ -457,7 +456,7 @@ impl<'a> fmt::Display for Unexpected<'a> {
|
|||||||
///
|
///
|
||||||
/// Outside of a `Visitor`, `&"..."` can be used.
|
/// Outside of a `Visitor`, `&"..."` can be used.
|
||||||
///
|
///
|
||||||
/// ```edition2018
|
/// ```edition2021
|
||||||
/// # use serde::de::{self, Unexpected};
|
/// # use serde::de::{self, Unexpected};
|
||||||
/// #
|
/// #
|
||||||
/// # fn example<E>() -> Result<(), E>
|
/// # fn example<E>() -> Result<(), E>
|
||||||
@@ -465,7 +464,10 @@ impl<'a> fmt::Display for Unexpected<'a> {
|
|||||||
/// # E: de::Error,
|
/// # E: de::Error,
|
||||||
/// # {
|
/// # {
|
||||||
/// # let v = true;
|
/// # let v = true;
|
||||||
/// return Err(de::Error::invalid_type(Unexpected::Bool(v), &"a negative integer"));
|
/// return Err(de::Error::invalid_type(
|
||||||
|
/// Unexpected::Bool(v),
|
||||||
|
/// &"a negative integer",
|
||||||
|
/// ));
|
||||||
/// # }
|
/// # }
|
||||||
/// ```
|
/// ```
|
||||||
pub trait Expected {
|
pub trait Expected {
|
||||||
@@ -577,7 +579,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.
|
||||||
///
|
///
|
||||||
/// ```edition2018
|
/// ```edition2021
|
||||||
/// # use serde::de::{Deserialize, DeserializeOwned};
|
/// # use serde::de::{Deserialize, DeserializeOwned};
|
||||||
/// # use std::io::{Read, Result};
|
/// # use std::io::{Read, Result};
|
||||||
/// #
|
/// #
|
||||||
@@ -616,7 +618,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:
|
||||||
///
|
///
|
||||||
/// ```edition2018
|
/// ```edition2021
|
||||||
/// # use serde::Deserialize;
|
/// # use serde::Deserialize;
|
||||||
/// #
|
/// #
|
||||||
/// # enum Error {}
|
/// # enum Error {}
|
||||||
@@ -630,7 +632,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:
|
||||||
///
|
///
|
||||||
/// ```edition2018
|
/// ```edition2021
|
||||||
/// # use serde::de::DeserializeSeed;
|
/// # use serde::de::DeserializeSeed;
|
||||||
/// #
|
/// #
|
||||||
/// # enum Error {}
|
/// # enum Error {}
|
||||||
@@ -663,12 +665,11 @@ 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.
|
||||||
///
|
///
|
||||||
/// ```edition2018
|
/// ```edition2021
|
||||||
|
/// use serde::de::{Deserialize, DeserializeSeed, Deserializer, SeqAccess, Visitor};
|
||||||
/// use std::fmt;
|
/// use std::fmt;
|
||||||
/// use std::marker::PhantomData;
|
/// use std::marker::PhantomData;
|
||||||
///
|
///
|
||||||
/// use serde::de::{Deserialize, DeserializeSeed, Deserializer, SeqAccess, Visitor};
|
|
||||||
///
|
|
||||||
/// // A DeserializeSeed implementation that uses stateful deserialization to
|
/// // A DeserializeSeed implementation that uses stateful deserialization to
|
||||||
/// // append array elements onto the end of an existing vector. The preexisting
|
/// // append array elements onto the end of an existing vector. The preexisting
|
||||||
/// // state ("seed") in this case is the Vec<T>. The `deserialize` method of
|
/// // state ("seed") in this case is the Vec<T>. The `deserialize` method of
|
||||||
@@ -709,7 +710,7 @@ impl<T> DeserializeOwned for T where T: for<'de> Deserialize<'de> {}
|
|||||||
/// {
|
/// {
|
||||||
/// // Decrease the number of reallocations if there are many elements
|
/// // Decrease the number of reallocations if there are many elements
|
||||||
/// if let Some(size_hint) = seq.size_hint() {
|
/// if let Some(size_hint) = seq.size_hint() {
|
||||||
/// self.0.reserve(size_hint);
|
/// self.0.reserve(size_hint);
|
||||||
/// }
|
/// }
|
||||||
///
|
///
|
||||||
/// // Visit each element in the inner array and push it onto
|
/// // Visit each element in the inner array and push it onto
|
||||||
@@ -1158,7 +1159,7 @@ pub trait Deserializer<'de>: Sized {
|
|||||||
/// human-readable one and binary formats like Postcard will prefer the
|
/// human-readable one and binary formats like Postcard will prefer the
|
||||||
/// compact one.
|
/// compact one.
|
||||||
///
|
///
|
||||||
/// ```edition2018
|
/// ```edition2021
|
||||||
/// # use std::ops::Add;
|
/// # use std::ops::Add;
|
||||||
/// # use std::str::FromStr;
|
/// # use std::str::FromStr;
|
||||||
/// #
|
/// #
|
||||||
@@ -1249,10 +1250,9 @@ pub trait Deserializer<'de>: Sized {
|
|||||||
///
|
///
|
||||||
/// # Example
|
/// # Example
|
||||||
///
|
///
|
||||||
/// ```edition2018
|
/// ```edition2021
|
||||||
/// # use std::fmt;
|
|
||||||
/// #
|
|
||||||
/// # use serde::de::{self, Unexpected, Visitor};
|
/// # use serde::de::{self, Unexpected, Visitor};
|
||||||
|
/// # use std::fmt;
|
||||||
/// #
|
/// #
|
||||||
/// /// A visitor that deserializes a long string - a string containing at least
|
/// /// A visitor that deserializes a long string - a string containing at least
|
||||||
/// /// some minimum number of bytes.
|
/// /// some minimum number of bytes.
|
||||||
@@ -1290,7 +1290,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.
|
||||||
///
|
///
|
||||||
/// ```edition2018
|
/// ```edition2021
|
||||||
/// # use std::fmt;
|
/// # use std::fmt;
|
||||||
/// #
|
/// #
|
||||||
/// # struct S {
|
/// # struct S {
|
||||||
@@ -2035,7 +2035,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:
|
||||||
///
|
///
|
||||||
/// ```edition2018
|
/// ```edition2021
|
||||||
/// # use serde::de::{self, value, DeserializeSeed, Visitor, VariantAccess, Unexpected};
|
/// # use serde::de::{self, value, DeserializeSeed, Visitor, VariantAccess, Unexpected};
|
||||||
/// #
|
/// #
|
||||||
/// # struct X;
|
/// # struct X;
|
||||||
@@ -2075,7 +2075,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:
|
||||||
///
|
///
|
||||||
/// ```edition2018
|
/// ```edition2021
|
||||||
/// # use serde::de::{self, value, DeserializeSeed, Visitor, VariantAccess, Unexpected};
|
/// # use serde::de::{self, value, DeserializeSeed, Visitor, VariantAccess, Unexpected};
|
||||||
/// #
|
/// #
|
||||||
/// # struct X;
|
/// # struct X;
|
||||||
@@ -2131,7 +2131,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:
|
||||||
///
|
///
|
||||||
/// ```edition2018
|
/// ```edition2021
|
||||||
/// # use serde::de::{self, value, DeserializeSeed, Visitor, VariantAccess, Unexpected};
|
/// # use serde::de::{self, value, DeserializeSeed, Visitor, VariantAccess, Unexpected};
|
||||||
/// #
|
/// #
|
||||||
/// # struct X;
|
/// # struct X;
|
||||||
@@ -2148,11 +2148,7 @@ pub trait VariantAccess<'de>: Sized {
|
|||||||
/// # T: DeserializeSeed<'de>,
|
/// # T: DeserializeSeed<'de>,
|
||||||
/// # { unimplemented!() }
|
/// # { unimplemented!() }
|
||||||
/// #
|
/// #
|
||||||
/// fn tuple_variant<V>(
|
/// fn tuple_variant<V>(self, _len: usize, _visitor: V) -> Result<V::Value, Self::Error>
|
||||||
/// self,
|
|
||||||
/// _len: usize,
|
|
||||||
/// _visitor: V,
|
|
||||||
/// ) -> Result<V::Value, Self::Error>
|
|
||||||
/// where
|
/// where
|
||||||
/// V: Visitor<'de>,
|
/// V: Visitor<'de>,
|
||||||
/// {
|
/// {
|
||||||
@@ -2178,7 +2174,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:
|
||||||
///
|
///
|
||||||
/// ```edition2018
|
/// ```edition2021
|
||||||
/// # use serde::de::{self, value, DeserializeSeed, Visitor, VariantAccess, Unexpected};
|
/// # use serde::de::{self, value, DeserializeSeed, Visitor, VariantAccess, Unexpected};
|
||||||
/// #
|
/// #
|
||||||
/// # struct X;
|
/// # struct X;
|
||||||
@@ -2238,10 +2234,10 @@ pub trait VariantAccess<'de>: Sized {
|
|||||||
///
|
///
|
||||||
/// # Example
|
/// # Example
|
||||||
///
|
///
|
||||||
/// ```edition2018
|
/// ```edition2021
|
||||||
|
/// use serde::de::{value, Deserialize, IntoDeserializer};
|
||||||
|
/// use serde_derive::Deserialize;
|
||||||
/// use std::str::FromStr;
|
/// use std::str::FromStr;
|
||||||
/// use serde::Deserialize;
|
|
||||||
/// use serde::de::{value, IntoDeserializer};
|
|
||||||
///
|
///
|
||||||
/// #[derive(Deserialize)]
|
/// #[derive(Deserialize)]
|
||||||
/// enum Setting {
|
/// enum Setting {
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
//! Building blocks for deserializing basic values using the `IntoDeserializer`
|
//! Building blocks for deserializing basic values using the `IntoDeserializer`
|
||||||
//! trait.
|
//! trait.
|
||||||
//!
|
//!
|
||||||
//! ```edition2018
|
//! ```edition2021
|
||||||
|
//! use serde::de::{value, Deserialize, IntoDeserializer};
|
||||||
|
//! use serde_derive::Deserialize;
|
||||||
//! use std::str::FromStr;
|
//! use std::str::FromStr;
|
||||||
//! use serde::Deserialize;
|
|
||||||
//! use serde::de::{value, IntoDeserializer};
|
|
||||||
//!
|
//!
|
||||||
//! #[derive(Deserialize)]
|
//! #[derive(Deserialize)]
|
||||||
//! enum Setting {
|
//! enum Setting {
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
/// or do not target platforms that lack 128-bit integers, do not need to
|
/// or do not target platforms that lack 128-bit integers, do not need to
|
||||||
/// bother with this macro and may assume support for 128-bit integers.
|
/// bother with this macro and may assume support for 128-bit integers.
|
||||||
///
|
///
|
||||||
/// ```edition2018
|
/// ```edition2021
|
||||||
/// # use serde::__private::doc::Error;
|
/// # use serde::__private::doc::Error;
|
||||||
/// #
|
/// #
|
||||||
/// # struct MySerializer;
|
/// # struct MySerializer;
|
||||||
@@ -50,7 +50,7 @@
|
|||||||
/// 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.
|
||||||
///
|
///
|
||||||
/// ```edition2018
|
/// ```edition2021
|
||||||
/// macro_rules! serde_if_integer128 {
|
/// macro_rules! serde_if_integer128 {
|
||||||
/// ($($tt:tt)*) => {
|
/// ($($tt:tt)*) => {
|
||||||
/// $($tt)*
|
/// $($tt)*
|
||||||
@@ -61,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.
|
||||||
///
|
///
|
||||||
/// ```edition2018
|
/// ```edition2021
|
||||||
/// macro_rules! serde_if_integer128 {
|
/// macro_rules! serde_if_integer128 {
|
||||||
/// ($($tt:tt)*) => {};
|
/// ($($tt:tt)*) => {};
|
||||||
/// }
|
/// }
|
||||||
|
|||||||
+2
-2
@@ -93,7 +93,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.165")]
|
#![doc(html_root_url = "https://docs.rs/serde/1.0.171")]
|
||||||
// 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
|
||||||
@@ -180,7 +180,7 @@ mod lib {
|
|||||||
pub use self::core::fmt::{self, Debug, Display};
|
pub use self::core::fmt::{self, Debug, Display};
|
||||||
pub use self::core::marker::{self, PhantomData};
|
pub use self::core::marker::{self, PhantomData};
|
||||||
pub use self::core::num::Wrapping;
|
pub use self::core::num::Wrapping;
|
||||||
pub use self::core::ops::Range;
|
pub use self::core::ops::{Range, RangeFrom, RangeTo};
|
||||||
pub use self::core::option::{self, Option};
|
pub use self::core::option::{self, Option};
|
||||||
pub use self::core::result::{self, Result};
|
pub use self::core::result::{self, Result};
|
||||||
|
|
||||||
|
|||||||
+4
-5
@@ -11,7 +11,7 @@
|
|||||||
/// input. This requires repetitive implementations of all the [`Deserializer`]
|
/// input. This requires repetitive implementations of all the [`Deserializer`]
|
||||||
/// trait methods.
|
/// trait methods.
|
||||||
///
|
///
|
||||||
/// ```edition2018
|
/// ```edition2021
|
||||||
/// # use serde::forward_to_deserialize_any;
|
/// # use serde::forward_to_deserialize_any;
|
||||||
/// # use serde::de::{value, Deserializer, Visitor};
|
/// # use serde::de::{value, Deserializer, Visitor};
|
||||||
/// #
|
/// #
|
||||||
@@ -47,7 +47,7 @@
|
|||||||
/// 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.
|
||||||
///
|
///
|
||||||
/// ```edition2018
|
/// ```edition2021
|
||||||
/// # use serde::forward_to_deserialize_any;
|
/// # use serde::forward_to_deserialize_any;
|
||||||
/// # use serde::de::{value, Deserializer, Visitor};
|
/// # use serde::de::{value, Deserializer, Visitor};
|
||||||
/// #
|
/// #
|
||||||
@@ -78,11 +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.
|
||||||
///
|
///
|
||||||
/// ```edition2018
|
/// ```edition2021
|
||||||
/// # use std::marker::PhantomData;
|
|
||||||
/// #
|
|
||||||
/// # use serde::forward_to_deserialize_any;
|
/// # use serde::forward_to_deserialize_any;
|
||||||
/// # use serde::de::{value, Deserializer, Visitor};
|
/// # use serde::de::{value, Deserializer, Visitor};
|
||||||
|
/// # use std::marker::PhantomData;
|
||||||
/// #
|
/// #
|
||||||
/// # struct MyDeserializer<V>(PhantomData<V>);
|
/// # struct MyDeserializer<V>(PhantomData<V>);
|
||||||
/// #
|
/// #
|
||||||
|
|||||||
+64
-41
@@ -474,7 +474,8 @@ mod content {
|
|||||||
where
|
where
|
||||||
V: SeqAccess<'de>,
|
V: SeqAccess<'de>,
|
||||||
{
|
{
|
||||||
let mut vec = Vec::with_capacity(size_hint::cautious(visitor.size_hint()));
|
let mut vec =
|
||||||
|
Vec::<Content>::with_capacity(size_hint::cautious::<Content>(visitor.size_hint()));
|
||||||
while let Some(e) = try!(visitor.next_element()) {
|
while let Some(e) = try!(visitor.next_element()) {
|
||||||
vec.push(e);
|
vec.push(e);
|
||||||
}
|
}
|
||||||
@@ -485,7 +486,10 @@ mod content {
|
|||||||
where
|
where
|
||||||
V: MapAccess<'de>,
|
V: MapAccess<'de>,
|
||||||
{
|
{
|
||||||
let mut vec = Vec::with_capacity(size_hint::cautious(visitor.size_hint()));
|
let mut vec =
|
||||||
|
Vec::<(Content, Content)>::with_capacity(
|
||||||
|
size_hint::cautious::<(Content, Content)>(visitor.size_hint()),
|
||||||
|
);
|
||||||
while let Some(kv) = try!(visitor.next_entry()) {
|
while let Some(kv) = try!(visitor.next_entry()) {
|
||||||
vec.push(kv);
|
vec.push(kv);
|
||||||
}
|
}
|
||||||
@@ -797,19 +801,13 @@ mod content {
|
|||||||
/// Used by generated code to deserialize an internally tagged enum.
|
/// Used by generated code to deserialize an internally tagged enum.
|
||||||
///
|
///
|
||||||
/// Not public API.
|
/// Not public API.
|
||||||
pub struct TaggedContent<'de, T> {
|
pub struct TaggedContentVisitor<T> {
|
||||||
pub tag: T,
|
|
||||||
pub content: Content<'de>,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Not public API.
|
|
||||||
pub struct TaggedContentVisitor<'de, T> {
|
|
||||||
tag_name: &'static str,
|
tag_name: &'static str,
|
||||||
expecting: &'static str,
|
expecting: &'static str,
|
||||||
value: PhantomData<TaggedContent<'de, T>>,
|
value: PhantomData<T>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'de, T> TaggedContentVisitor<'de, T> {
|
impl<T> TaggedContentVisitor<T> {
|
||||||
/// Visitor for the content of an internally tagged enum with the given
|
/// Visitor for the content of an internally tagged enum with the given
|
||||||
/// tag name.
|
/// tag name.
|
||||||
pub fn new(name: &'static str, expecting: &'static str) -> Self {
|
pub fn new(name: &'static str, expecting: &'static str) -> Self {
|
||||||
@@ -821,27 +819,11 @@ mod content {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'de, T> DeserializeSeed<'de> for TaggedContentVisitor<'de, T>
|
impl<'de, T> Visitor<'de> for TaggedContentVisitor<T>
|
||||||
where
|
where
|
||||||
T: Deserialize<'de>,
|
T: Deserialize<'de>,
|
||||||
{
|
{
|
||||||
type Value = TaggedContent<'de, T>;
|
type Value = (T, Content<'de>);
|
||||||
|
|
||||||
fn deserialize<D>(self, deserializer: D) -> Result<Self::Value, D::Error>
|
|
||||||
where
|
|
||||||
D: Deserializer<'de>,
|
|
||||||
{
|
|
||||||
// Internally tagged enums are only supported in self-describing
|
|
||||||
// formats.
|
|
||||||
deserializer.deserialize_any(self)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'de, T> Visitor<'de> for TaggedContentVisitor<'de, T>
|
|
||||||
where
|
|
||||||
T: Deserialize<'de>,
|
|
||||||
{
|
|
||||||
type Value = TaggedContent<'de, T>;
|
|
||||||
|
|
||||||
fn expecting(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
fn expecting(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||||
fmt.write_str(self.expecting)
|
fmt.write_str(self.expecting)
|
||||||
@@ -858,10 +840,7 @@ mod content {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
let rest = de::value::SeqAccessDeserializer::new(seq);
|
let rest = de::value::SeqAccessDeserializer::new(seq);
|
||||||
Ok(TaggedContent {
|
Ok((tag, try!(Content::deserialize(rest))))
|
||||||
tag,
|
|
||||||
content: try!(Content::deserialize(rest)),
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error>
|
fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error>
|
||||||
@@ -869,7 +848,10 @@ mod content {
|
|||||||
M: MapAccess<'de>,
|
M: MapAccess<'de>,
|
||||||
{
|
{
|
||||||
let mut tag = None;
|
let mut tag = None;
|
||||||
let mut vec = Vec::with_capacity(size_hint::cautious(map.size_hint()));
|
let mut vec = Vec::<(Content, Content)>::with_capacity(size_hint::cautious::<(
|
||||||
|
Content,
|
||||||
|
Content,
|
||||||
|
)>(map.size_hint()));
|
||||||
while let Some(k) = try!(map.next_key_seed(TagOrContentVisitor::new(self.tag_name))) {
|
while let Some(k) = try!(map.next_key_seed(TagOrContentVisitor::new(self.tag_name))) {
|
||||||
match k {
|
match k {
|
||||||
TagOrContent::Tag => {
|
TagOrContent::Tag => {
|
||||||
@@ -886,10 +868,7 @@ mod content {
|
|||||||
}
|
}
|
||||||
match tag {
|
match tag {
|
||||||
None => Err(de::Error::missing_field(self.tag_name)),
|
None => Err(de::Error::missing_field(self.tag_name)),
|
||||||
Some(tag) => Ok(TaggedContent {
|
Some(tag) => Ok((tag, Content::Map(vec))),
|
||||||
tag,
|
|
||||||
content: Content::Map(vec),
|
|
||||||
}),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -915,7 +894,7 @@ mod content {
|
|||||||
where
|
where
|
||||||
D: Deserializer<'de>,
|
D: Deserializer<'de>,
|
||||||
{
|
{
|
||||||
deserializer.deserialize_str(self)
|
deserializer.deserialize_identifier(self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -926,6 +905,20 @@ mod content {
|
|||||||
write!(formatter, "{:?} or {:?}", self.tag, self.content)
|
write!(formatter, "{:?} or {:?}", self.tag, self.content)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn visit_u64<E>(self, field_index: u64) -> Result<Self::Value, E>
|
||||||
|
where
|
||||||
|
E: de::Error,
|
||||||
|
{
|
||||||
|
match field_index {
|
||||||
|
0 => Ok(TagOrContentField::Tag),
|
||||||
|
1 => Ok(TagOrContentField::Content),
|
||||||
|
_ => Err(de::Error::invalid_value(
|
||||||
|
Unexpected::Unsigned(field_index),
|
||||||
|
&self,
|
||||||
|
)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn visit_str<E>(self, field: &str) -> Result<Self::Value, E>
|
fn visit_str<E>(self, field: &str) -> Result<Self::Value, E>
|
||||||
where
|
where
|
||||||
E: de::Error,
|
E: de::Error,
|
||||||
@@ -938,6 +931,19 @@ mod content {
|
|||||||
Err(de::Error::invalid_value(Unexpected::Str(field), &self))
|
Err(de::Error::invalid_value(Unexpected::Str(field), &self))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn visit_bytes<E>(self, field: &[u8]) -> Result<Self::Value, E>
|
||||||
|
where
|
||||||
|
E: de::Error,
|
||||||
|
{
|
||||||
|
if field == self.tag.as_bytes() {
|
||||||
|
Ok(TagOrContentField::Tag)
|
||||||
|
} else if field == self.content.as_bytes() {
|
||||||
|
Ok(TagOrContentField::Content)
|
||||||
|
} else {
|
||||||
|
Err(de::Error::invalid_value(Unexpected::Bytes(field), &self))
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Used by generated code to deserialize an adjacently tagged enum when
|
/// Used by generated code to deserialize an adjacently tagged enum when
|
||||||
@@ -963,7 +969,7 @@ mod content {
|
|||||||
where
|
where
|
||||||
D: Deserializer<'de>,
|
D: Deserializer<'de>,
|
||||||
{
|
{
|
||||||
deserializer.deserialize_str(self)
|
deserializer.deserialize_identifier(self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -978,6 +984,17 @@ mod content {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn visit_u64<E>(self, field_index: u64) -> Result<Self::Value, E>
|
||||||
|
where
|
||||||
|
E: de::Error,
|
||||||
|
{
|
||||||
|
match field_index {
|
||||||
|
0 => Ok(TagContentOtherField::Tag),
|
||||||
|
1 => Ok(TagContentOtherField::Content),
|
||||||
|
_ => Ok(TagContentOtherField::Other),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn visit_str<E>(self, field: &str) -> Result<Self::Value, E>
|
fn visit_str<E>(self, field: &str) -> Result<Self::Value, E>
|
||||||
where
|
where
|
||||||
E: de::Error,
|
E: de::Error,
|
||||||
@@ -2822,6 +2839,13 @@ where
|
|||||||
visitor.visit_unit()
|
visitor.visit_unit()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn deserialize_ignored_any<V>(self, visitor: V) -> Result<V::Value, Self::Error>
|
||||||
|
where
|
||||||
|
V: Visitor<'de>,
|
||||||
|
{
|
||||||
|
visitor.visit_unit()
|
||||||
|
}
|
||||||
|
|
||||||
forward_to_deserialize_other! {
|
forward_to_deserialize_other! {
|
||||||
deserialize_bool()
|
deserialize_bool()
|
||||||
deserialize_i8()
|
deserialize_i8()
|
||||||
@@ -2844,7 +2868,6 @@ where
|
|||||||
deserialize_tuple(usize)
|
deserialize_tuple(usize)
|
||||||
deserialize_tuple_struct(&'static str, usize)
|
deserialize_tuple_struct(&'static str, usize)
|
||||||
deserialize_identifier()
|
deserialize_identifier()
|
||||||
deserialize_ignored_any()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,9 +8,17 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(any(feature = "std", feature = "alloc"))]
|
#[cfg(any(feature = "std", feature = "alloc"))]
|
||||||
#[inline]
|
pub fn cautious<Element>(hint: Option<usize>) -> usize {
|
||||||
pub fn cautious(hint: Option<usize>) -> usize {
|
const MAX_PREALLOC_BYTES: usize = 1024 * 1024;
|
||||||
cmp::min(hint.unwrap_or(0), 4096)
|
|
||||||
|
if mem::size_of::<Element>() == 0 {
|
||||||
|
0
|
||||||
|
} else {
|
||||||
|
cmp::min(
|
||||||
|
hint.unwrap_or(0),
|
||||||
|
MAX_PREALLOC_BYTES / mem::size_of::<Element>(),
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn helper(bounds: (usize, Option<usize>)) -> Option<usize> {
|
fn helper(bounds: (usize, Option<usize>)) -> Option<usize> {
|
||||||
|
|||||||
@@ -17,8 +17,9 @@ macro_rules! fmt_primitives {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/// ```edition2018
|
/// ```edition2021
|
||||||
/// use serde::Serialize;
|
/// use serde::ser::Serialize;
|
||||||
|
/// use serde_derive::Serialize;
|
||||||
/// use std::fmt::{self, Display};
|
/// use std::fmt::{self, Display};
|
||||||
///
|
///
|
||||||
/// #[derive(Serialize)]
|
/// #[derive(Serialize)]
|
||||||
|
|||||||
@@ -257,6 +257,23 @@ where
|
|||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
impl<Idx> Serialize for RangeFrom<Idx>
|
||||||
|
where
|
||||||
|
Idx: Serialize,
|
||||||
|
{
|
||||||
|
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||||
|
where
|
||||||
|
S: Serializer,
|
||||||
|
{
|
||||||
|
use super::SerializeStruct;
|
||||||
|
let mut state = try!(serializer.serialize_struct("RangeFrom", 1));
|
||||||
|
try!(state.serialize_field("start", &self.start));
|
||||||
|
state.end()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#[cfg(not(no_range_inclusive))]
|
#[cfg(not(no_range_inclusive))]
|
||||||
impl<Idx> Serialize for RangeInclusive<Idx>
|
impl<Idx> Serialize for RangeInclusive<Idx>
|
||||||
where
|
where
|
||||||
@@ -276,6 +293,23 @@ where
|
|||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
impl<Idx> Serialize for RangeTo<Idx>
|
||||||
|
where
|
||||||
|
Idx: Serialize,
|
||||||
|
{
|
||||||
|
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||||
|
where
|
||||||
|
S: Serializer,
|
||||||
|
{
|
||||||
|
use super::SerializeStruct;
|
||||||
|
let mut state = try!(serializer.serialize_struct("RangeTo", 1));
|
||||||
|
try!(state.serialize_field("end", &self.end));
|
||||||
|
state.end()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#[cfg(any(not(no_ops_bound), all(feature = "std", not(no_collections_bound))))]
|
#[cfg(any(not(no_ops_bound), all(feature = "std", not(no_collections_bound))))]
|
||||||
impl<T> Serialize for Bound<T>
|
impl<T> Serialize for Bound<T>
|
||||||
where
|
where
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ use ser::{
|
|||||||
/// [`SerializeTuple`], [`SerializeTupleStruct`], [`SerializeTupleVariant`],
|
/// [`SerializeTuple`], [`SerializeTupleStruct`], [`SerializeTupleVariant`],
|
||||||
/// [`SerializeMap`], [`SerializeStruct`], and [`SerializeStructVariant`].
|
/// [`SerializeMap`], [`SerializeStruct`], and [`SerializeStructVariant`].
|
||||||
///
|
///
|
||||||
/// ```edition2018
|
/// ```edition2021
|
||||||
/// # use serde::ser::{Serializer, Impossible};
|
/// # use serde::ser::{Serializer, Impossible};
|
||||||
/// # use serde::__private::doc::Error;
|
/// # use serde::__private::doc::Error;
|
||||||
/// #
|
/// #
|
||||||
|
|||||||
+60
-64
@@ -149,7 +149,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.
|
||||||
///
|
///
|
||||||
/// ```edition2018
|
/// ```edition2021
|
||||||
/// # struct Path;
|
/// # struct Path;
|
||||||
/// #
|
/// #
|
||||||
/// # impl Path {
|
/// # impl Path {
|
||||||
@@ -221,7 +221,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.
|
||||||
///
|
///
|
||||||
/// ```edition2018
|
/// ```edition2021
|
||||||
/// use serde::ser::{Serialize, SerializeStruct, Serializer};
|
/// use serde::ser::{Serialize, SerializeStruct, Serializer};
|
||||||
///
|
///
|
||||||
/// struct Person {
|
/// struct Person {
|
||||||
@@ -388,7 +388,7 @@ pub trait Serializer: Sized {
|
|||||||
|
|
||||||
/// Serialize a `bool` value.
|
/// Serialize a `bool` value.
|
||||||
///
|
///
|
||||||
/// ```edition2018
|
/// ```edition2021
|
||||||
/// # use serde::Serializer;
|
/// # use serde::Serializer;
|
||||||
/// #
|
/// #
|
||||||
/// # serde::__private_serialize!();
|
/// # serde::__private_serialize!();
|
||||||
@@ -410,7 +410,7 @@ 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`.
|
||||||
///
|
///
|
||||||
/// ```edition2018
|
/// ```edition2021
|
||||||
/// # use serde::Serializer;
|
/// # use serde::Serializer;
|
||||||
/// #
|
/// #
|
||||||
/// # serde::__private_serialize!();
|
/// # serde::__private_serialize!();
|
||||||
@@ -432,7 +432,7 @@ 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`.
|
||||||
///
|
///
|
||||||
/// ```edition2018
|
/// ```edition2021
|
||||||
/// # use serde::Serializer;
|
/// # use serde::Serializer;
|
||||||
/// #
|
/// #
|
||||||
/// # serde::__private_serialize!();
|
/// # serde::__private_serialize!();
|
||||||
@@ -454,7 +454,7 @@ 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`.
|
||||||
///
|
///
|
||||||
/// ```edition2018
|
/// ```edition2021
|
||||||
/// # use serde::Serializer;
|
/// # use serde::Serializer;
|
||||||
/// #
|
/// #
|
||||||
/// # serde::__private_serialize!();
|
/// # serde::__private_serialize!();
|
||||||
@@ -472,7 +472,7 @@ pub trait Serializer: Sized {
|
|||||||
|
|
||||||
/// Serialize an `i64` value.
|
/// Serialize an `i64` value.
|
||||||
///
|
///
|
||||||
/// ```edition2018
|
/// ```edition2021
|
||||||
/// # use serde::Serializer;
|
/// # use serde::Serializer;
|
||||||
/// #
|
/// #
|
||||||
/// # serde::__private_serialize!();
|
/// # serde::__private_serialize!();
|
||||||
@@ -491,7 +491,7 @@ pub trait Serializer: Sized {
|
|||||||
serde_if_integer128! {
|
serde_if_integer128! {
|
||||||
/// Serialize an `i128` value.
|
/// Serialize an `i128` value.
|
||||||
///
|
///
|
||||||
/// ```edition2018
|
/// ```edition2021
|
||||||
/// # use serde::Serializer;
|
/// # use serde::Serializer;
|
||||||
/// #
|
/// #
|
||||||
/// # serde::__private_serialize!();
|
/// # serde::__private_serialize!();
|
||||||
@@ -520,7 +520,7 @@ 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`.
|
||||||
///
|
///
|
||||||
/// ```edition2018
|
/// ```edition2021
|
||||||
/// # use serde::Serializer;
|
/// # use serde::Serializer;
|
||||||
/// #
|
/// #
|
||||||
/// # serde::__private_serialize!();
|
/// # serde::__private_serialize!();
|
||||||
@@ -542,7 +542,7 @@ 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`.
|
||||||
///
|
///
|
||||||
/// ```edition2018
|
/// ```edition2021
|
||||||
/// # use serde::Serializer;
|
/// # use serde::Serializer;
|
||||||
/// #
|
/// #
|
||||||
/// # serde::__private_serialize!();
|
/// # serde::__private_serialize!();
|
||||||
@@ -564,7 +564,7 @@ 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`.
|
||||||
///
|
///
|
||||||
/// ```edition2018
|
/// ```edition2021
|
||||||
/// # use serde::Serializer;
|
/// # use serde::Serializer;
|
||||||
/// #
|
/// #
|
||||||
/// # serde::__private_serialize!();
|
/// # serde::__private_serialize!();
|
||||||
@@ -582,7 +582,7 @@ pub trait Serializer: Sized {
|
|||||||
|
|
||||||
/// Serialize a `u64` value.
|
/// Serialize a `u64` value.
|
||||||
///
|
///
|
||||||
/// ```edition2018
|
/// ```edition2021
|
||||||
/// # use serde::Serializer;
|
/// # use serde::Serializer;
|
||||||
/// #
|
/// #
|
||||||
/// # serde::__private_serialize!();
|
/// # serde::__private_serialize!();
|
||||||
@@ -601,7 +601,7 @@ pub trait Serializer: Sized {
|
|||||||
serde_if_integer128! {
|
serde_if_integer128! {
|
||||||
/// Serialize a `u128` value.
|
/// Serialize a `u128` value.
|
||||||
///
|
///
|
||||||
/// ```edition2018
|
/// ```edition2021
|
||||||
/// # use serde::Serializer;
|
/// # use serde::Serializer;
|
||||||
/// #
|
/// #
|
||||||
/// # serde::__private_serialize!();
|
/// # serde::__private_serialize!();
|
||||||
@@ -630,7 +630,7 @@ 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`.
|
||||||
///
|
///
|
||||||
/// ```edition2018
|
/// ```edition2021
|
||||||
/// # use serde::Serializer;
|
/// # use serde::Serializer;
|
||||||
/// #
|
/// #
|
||||||
/// # serde::__private_serialize!();
|
/// # serde::__private_serialize!();
|
||||||
@@ -648,7 +648,7 @@ pub trait Serializer: Sized {
|
|||||||
|
|
||||||
/// Serialize an `f64` value.
|
/// Serialize an `f64` value.
|
||||||
///
|
///
|
||||||
/// ```edition2018
|
/// ```edition2021
|
||||||
/// # use serde::Serializer;
|
/// # use serde::Serializer;
|
||||||
/// #
|
/// #
|
||||||
/// # serde::__private_serialize!();
|
/// # serde::__private_serialize!();
|
||||||
@@ -669,7 +669,7 @@ 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`.
|
||||||
///
|
///
|
||||||
/// ```edition2018
|
/// ```edition2021
|
||||||
/// # use serde::Serializer;
|
/// # use serde::Serializer;
|
||||||
/// #
|
/// #
|
||||||
/// # serde::__private_serialize!();
|
/// # serde::__private_serialize!();
|
||||||
@@ -687,7 +687,7 @@ pub trait Serializer: Sized {
|
|||||||
|
|
||||||
/// Serialize a `&str`.
|
/// Serialize a `&str`.
|
||||||
///
|
///
|
||||||
/// ```edition2018
|
/// ```edition2021
|
||||||
/// # use serde::Serializer;
|
/// # use serde::Serializer;
|
||||||
/// #
|
/// #
|
||||||
/// # serde::__private_serialize!();
|
/// # serde::__private_serialize!();
|
||||||
@@ -711,7 +711,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:
|
||||||
///
|
///
|
||||||
/// ```edition2018
|
/// ```edition2021
|
||||||
/// # use serde::ser::{Serializer, SerializeSeq};
|
/// # use serde::ser::{Serializer, SerializeSeq};
|
||||||
/// # use serde::__private::doc::Error;
|
/// # use serde::__private::doc::Error;
|
||||||
/// #
|
/// #
|
||||||
@@ -740,7 +740,7 @@ pub trait Serializer: Sized {
|
|||||||
|
|
||||||
/// Serialize a [`None`] value.
|
/// Serialize a [`None`] value.
|
||||||
///
|
///
|
||||||
/// ```edition2018
|
/// ```edition2021
|
||||||
/// # use serde::{Serialize, Serializer};
|
/// # use serde::{Serialize, Serializer};
|
||||||
/// #
|
/// #
|
||||||
/// # enum Option<T> {
|
/// # enum Option<T> {
|
||||||
@@ -773,7 +773,7 @@ pub trait Serializer: Sized {
|
|||||||
|
|
||||||
/// Serialize a [`Some(T)`] value.
|
/// Serialize a [`Some(T)`] value.
|
||||||
///
|
///
|
||||||
/// ```edition2018
|
/// ```edition2021
|
||||||
/// # use serde::{Serialize, Serializer};
|
/// # use serde::{Serialize, Serializer};
|
||||||
/// #
|
/// #
|
||||||
/// # enum Option<T> {
|
/// # enum Option<T> {
|
||||||
@@ -808,7 +808,7 @@ pub trait Serializer: Sized {
|
|||||||
|
|
||||||
/// Serialize a `()` value.
|
/// Serialize a `()` value.
|
||||||
///
|
///
|
||||||
/// ```edition2018
|
/// ```edition2021
|
||||||
/// # use serde::Serializer;
|
/// # use serde::Serializer;
|
||||||
/// #
|
/// #
|
||||||
/// # serde::__private_serialize!();
|
/// # serde::__private_serialize!();
|
||||||
@@ -828,7 +828,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`.
|
||||||
///
|
///
|
||||||
/// ```edition2018
|
/// ```edition2021
|
||||||
/// use serde::{Serialize, Serializer};
|
/// use serde::{Serialize, Serializer};
|
||||||
///
|
///
|
||||||
/// struct Nothing;
|
/// struct Nothing;
|
||||||
@@ -850,7 +850,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.
|
||||||
///
|
///
|
||||||
/// ```edition2018
|
/// ```edition2021
|
||||||
/// use serde::{Serialize, Serializer};
|
/// use serde::{Serialize, Serializer};
|
||||||
///
|
///
|
||||||
/// enum E {
|
/// enum E {
|
||||||
@@ -883,7 +883,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)`.
|
||||||
///
|
///
|
||||||
/// ```edition2018
|
/// ```edition2021
|
||||||
/// use serde::{Serialize, Serializer};
|
/// use serde::{Serialize, Serializer};
|
||||||
///
|
///
|
||||||
/// struct Millimeters(u8);
|
/// struct Millimeters(u8);
|
||||||
@@ -911,7 +911,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.
|
||||||
///
|
///
|
||||||
/// ```edition2018
|
/// ```edition2021
|
||||||
/// use serde::{Serialize, Serializer};
|
/// use serde::{Serialize, Serializer};
|
||||||
///
|
///
|
||||||
/// enum E {
|
/// enum E {
|
||||||
@@ -949,7 +949,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.
|
||||||
///
|
///
|
||||||
/// ```edition2018
|
/// ```edition2021
|
||||||
/// # use std::marker::PhantomData;
|
/// # use std::marker::PhantomData;
|
||||||
/// #
|
/// #
|
||||||
/// # struct Vec<T>(PhantomData<T>);
|
/// # struct Vec<T>(PhantomData<T>);
|
||||||
@@ -962,14 +962,14 @@ pub trait Serializer: Sized {
|
|||||||
/// #
|
/// #
|
||||||
/// # impl<'a, T> IntoIterator for &'a Vec<T> {
|
/// # impl<'a, T> IntoIterator for &'a Vec<T> {
|
||||||
/// # type Item = &'a T;
|
/// # type Item = &'a T;
|
||||||
/// # type IntoIter = Box<Iterator<Item = &'a T>>;
|
/// # type IntoIter = Box<dyn Iterator<Item = &'a T>>;
|
||||||
/// #
|
/// #
|
||||||
/// # fn into_iter(self) -> Self::IntoIter {
|
/// # fn into_iter(self) -> Self::IntoIter {
|
||||||
/// # unimplemented!()
|
/// # unimplemented!()
|
||||||
/// # }
|
/// # }
|
||||||
/// # }
|
/// # }
|
||||||
/// #
|
/// #
|
||||||
/// use serde::ser::{Serialize, Serializer, SerializeSeq};
|
/// use serde::ser::{Serialize, SerializeSeq, Serializer};
|
||||||
///
|
///
|
||||||
/// impl<T> Serialize for Vec<T>
|
/// impl<T> Serialize for Vec<T>
|
||||||
/// where
|
/// where
|
||||||
@@ -994,8 +994,8 @@ 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`.
|
||||||
///
|
///
|
||||||
/// ```edition2018
|
/// ```edition2021
|
||||||
/// use serde::ser::{Serialize, Serializer, SerializeTuple};
|
/// use serde::ser::{Serialize, SerializeTuple, Serializer};
|
||||||
///
|
///
|
||||||
/// # mod fool {
|
/// # mod fool {
|
||||||
/// # trait Serialize {}
|
/// # trait Serialize {}
|
||||||
@@ -1024,7 +1024,7 @@ pub trait Serializer: Sized {
|
|||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// ```edition2018
|
/// ```edition2021
|
||||||
/// use serde::ser::{Serialize, SerializeTuple, Serializer};
|
/// use serde::ser::{Serialize, SerializeTuple, Serializer};
|
||||||
///
|
///
|
||||||
/// const VRAM_SIZE: usize = 386;
|
/// const VRAM_SIZE: usize = 386;
|
||||||
@@ -1052,7 +1052,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.
|
||||||
///
|
///
|
||||||
/// ```edition2018
|
/// ```edition2021
|
||||||
/// use serde::ser::{Serialize, SerializeTupleStruct, Serializer};
|
/// use serde::ser::{Serialize, SerializeTupleStruct, Serializer};
|
||||||
///
|
///
|
||||||
/// struct Rgb(u8, u8, u8);
|
/// struct Rgb(u8, u8, u8);
|
||||||
@@ -1084,7 +1084,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.
|
||||||
///
|
///
|
||||||
/// ```edition2018
|
/// ```edition2021
|
||||||
/// use serde::ser::{Serialize, SerializeTupleVariant, Serializer};
|
/// use serde::ser::{Serialize, SerializeTupleVariant, Serializer};
|
||||||
///
|
///
|
||||||
/// enum E {
|
/// enum E {
|
||||||
@@ -1130,7 +1130,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.
|
||||||
///
|
///
|
||||||
/// ```edition2018
|
/// ```edition2021
|
||||||
/// # use std::marker::PhantomData;
|
/// # use std::marker::PhantomData;
|
||||||
/// #
|
/// #
|
||||||
/// # struct HashMap<K, V>(PhantomData<K>, PhantomData<V>);
|
/// # struct HashMap<K, V>(PhantomData<K>, PhantomData<V>);
|
||||||
@@ -1143,14 +1143,14 @@ pub trait Serializer: Sized {
|
|||||||
/// #
|
/// #
|
||||||
/// # impl<'a, K, V> IntoIterator for &'a HashMap<K, V> {
|
/// # impl<'a, K, V> IntoIterator for &'a HashMap<K, V> {
|
||||||
/// # type Item = (&'a K, &'a V);
|
/// # type Item = (&'a K, &'a V);
|
||||||
/// # type IntoIter = Box<Iterator<Item = (&'a K, &'a V)>>;
|
/// # type IntoIter = Box<dyn Iterator<Item = (&'a K, &'a V)>>;
|
||||||
/// #
|
/// #
|
||||||
/// # fn into_iter(self) -> Self::IntoIter {
|
/// # fn into_iter(self) -> Self::IntoIter {
|
||||||
/// # unimplemented!()
|
/// # unimplemented!()
|
||||||
/// # }
|
/// # }
|
||||||
/// # }
|
/// # }
|
||||||
/// #
|
/// #
|
||||||
/// use serde::ser::{Serialize, Serializer, SerializeMap};
|
/// use serde::ser::{Serialize, SerializeMap, Serializer};
|
||||||
///
|
///
|
||||||
/// impl<K, V> Serialize for HashMap<K, V>
|
/// impl<K, V> Serialize for HashMap<K, V>
|
||||||
/// where
|
/// where
|
||||||
@@ -1178,7 +1178,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.
|
||||||
///
|
///
|
||||||
/// ```edition2018
|
/// ```edition2021
|
||||||
/// use serde::ser::{Serialize, SerializeStruct, Serializer};
|
/// use serde::ser::{Serialize, SerializeStruct, Serializer};
|
||||||
///
|
///
|
||||||
/// struct Rgb {
|
/// struct Rgb {
|
||||||
@@ -1214,7 +1214,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.
|
||||||
///
|
///
|
||||||
/// ```edition2018
|
/// ```edition2021
|
||||||
/// use serde::ser::{Serialize, SerializeStructVariant, Serializer};
|
/// use serde::ser::{Serialize, SerializeStructVariant, Serializer};
|
||||||
///
|
///
|
||||||
/// enum E {
|
/// enum E {
|
||||||
@@ -1256,7 +1256,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.
|
||||||
///
|
///
|
||||||
/// ```edition2018
|
/// ```edition2021
|
||||||
/// use serde::{Serialize, Serializer};
|
/// use serde::{Serialize, Serializer};
|
||||||
///
|
///
|
||||||
/// struct SecretlyOneHigher {
|
/// struct SecretlyOneHigher {
|
||||||
@@ -1304,7 +1304,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.
|
||||||
///
|
///
|
||||||
/// ```edition2018
|
/// ```edition2021
|
||||||
/// use serde::{Serialize, Serializer};
|
/// use serde::{Serialize, Serializer};
|
||||||
/// use std::collections::BTreeSet;
|
/// use std::collections::BTreeSet;
|
||||||
///
|
///
|
||||||
@@ -1355,7 +1355,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.
|
||||||
///
|
///
|
||||||
/// ```edition2018
|
/// ```edition2021
|
||||||
/// # struct DateTime;
|
/// # struct DateTime;
|
||||||
/// #
|
/// #
|
||||||
/// # impl DateTime {
|
/// # impl DateTime {
|
||||||
@@ -1370,9 +1370,7 @@ pub trait Serializer: Sized {
|
|||||||
/// where
|
/// where
|
||||||
/// S: Serializer,
|
/// S: Serializer,
|
||||||
/// {
|
/// {
|
||||||
/// serializer.collect_str(&format_args!("{:?}{:?}",
|
/// serializer.collect_str(&format_args!("{:?}{:?}", self.naive_local(), self.offset()))
|
||||||
/// self.naive_local(),
|
|
||||||
/// self.offset()))
|
|
||||||
/// }
|
/// }
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
@@ -1393,7 +1391,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.
|
||||||
///
|
///
|
||||||
/// ```edition2018
|
/// ```edition2021
|
||||||
/// # struct DateTime;
|
/// # struct DateTime;
|
||||||
/// #
|
/// #
|
||||||
/// # impl DateTime {
|
/// # impl DateTime {
|
||||||
@@ -1408,9 +1406,7 @@ pub trait Serializer: Sized {
|
|||||||
/// where
|
/// where
|
||||||
/// S: Serializer,
|
/// S: Serializer,
|
||||||
/// {
|
/// {
|
||||||
/// serializer.collect_str(&format_args!("{:?}{:?}",
|
/// serializer.collect_str(&format_args!("{:?}{:?}", self.naive_local(), self.offset()))
|
||||||
/// self.naive_local(),
|
|
||||||
/// self.offset()))
|
|
||||||
/// }
|
/// }
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
@@ -1428,7 +1424,7 @@ pub trait Serializer: Sized {
|
|||||||
/// human-readable one and binary formats like Postcard will prefer the
|
/// human-readable one and binary formats like Postcard will prefer the
|
||||||
/// compact one.
|
/// compact one.
|
||||||
///
|
///
|
||||||
/// ```edition2018
|
/// ```edition2021
|
||||||
/// # use std::fmt::{self, Display};
|
/// # use std::fmt::{self, Display};
|
||||||
/// #
|
/// #
|
||||||
/// # struct Timestamp;
|
/// # struct Timestamp;
|
||||||
@@ -1477,7 +1473,7 @@ pub trait Serializer: Sized {
|
|||||||
///
|
///
|
||||||
/// # Example use
|
/// # Example use
|
||||||
///
|
///
|
||||||
/// ```edition2018
|
/// ```edition2021
|
||||||
/// # use std::marker::PhantomData;
|
/// # use std::marker::PhantomData;
|
||||||
/// #
|
/// #
|
||||||
/// # struct Vec<T>(PhantomData<T>);
|
/// # struct Vec<T>(PhantomData<T>);
|
||||||
@@ -1490,13 +1486,13 @@ pub trait Serializer: Sized {
|
|||||||
/// #
|
/// #
|
||||||
/// # impl<'a, T> IntoIterator for &'a Vec<T> {
|
/// # impl<'a, T> IntoIterator for &'a Vec<T> {
|
||||||
/// # type Item = &'a T;
|
/// # type Item = &'a T;
|
||||||
/// # type IntoIter = Box<Iterator<Item = &'a T>>;
|
/// # type IntoIter = Box<dyn Iterator<Item = &'a T>>;
|
||||||
/// # fn into_iter(self) -> Self::IntoIter {
|
/// # fn into_iter(self) -> Self::IntoIter {
|
||||||
/// # unimplemented!()
|
/// # unimplemented!()
|
||||||
/// # }
|
/// # }
|
||||||
/// # }
|
/// # }
|
||||||
/// #
|
/// #
|
||||||
/// use serde::ser::{Serialize, Serializer, SerializeSeq};
|
/// use serde::ser::{Serialize, SerializeSeq, Serializer};
|
||||||
///
|
///
|
||||||
/// impl<T> Serialize for Vec<T>
|
/// impl<T> Serialize for Vec<T>
|
||||||
/// where
|
/// where
|
||||||
@@ -1541,8 +1537,8 @@ pub trait SerializeSeq {
|
|||||||
///
|
///
|
||||||
/// # Example use
|
/// # Example use
|
||||||
///
|
///
|
||||||
/// ```edition2018
|
/// ```edition2021
|
||||||
/// use serde::ser::{Serialize, Serializer, SerializeTuple};
|
/// use serde::ser::{Serialize, SerializeTuple, Serializer};
|
||||||
///
|
///
|
||||||
/// # mod fool {
|
/// # mod fool {
|
||||||
/// # trait Serialize {}
|
/// # trait Serialize {}
|
||||||
@@ -1571,7 +1567,7 @@ pub trait SerializeSeq {
|
|||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// ```edition2018
|
/// ```edition2021
|
||||||
/// # use std::marker::PhantomData;
|
/// # use std::marker::PhantomData;
|
||||||
/// #
|
/// #
|
||||||
/// # struct Array<T>(PhantomData<T>);
|
/// # struct Array<T>(PhantomData<T>);
|
||||||
@@ -1584,13 +1580,13 @@ pub trait SerializeSeq {
|
|||||||
/// #
|
/// #
|
||||||
/// # impl<'a, T> IntoIterator for &'a Array<T> {
|
/// # impl<'a, T> IntoIterator for &'a Array<T> {
|
||||||
/// # type Item = &'a T;
|
/// # type Item = &'a T;
|
||||||
/// # type IntoIter = Box<Iterator<Item = &'a T>>;
|
/// # type IntoIter = Box<dyn Iterator<Item = &'a T>>;
|
||||||
/// # fn into_iter(self) -> Self::IntoIter {
|
/// # fn into_iter(self) -> Self::IntoIter {
|
||||||
/// # unimplemented!()
|
/// # unimplemented!()
|
||||||
/// # }
|
/// # }
|
||||||
/// # }
|
/// # }
|
||||||
/// #
|
/// #
|
||||||
/// use serde::ser::{Serialize, Serializer, SerializeTuple};
|
/// use serde::ser::{Serialize, SerializeTuple, Serializer};
|
||||||
///
|
///
|
||||||
/// # mod fool {
|
/// # mod fool {
|
||||||
/// # trait Serialize {}
|
/// # trait Serialize {}
|
||||||
@@ -1641,7 +1637,7 @@ pub trait SerializeTuple {
|
|||||||
///
|
///
|
||||||
/// # Example use
|
/// # Example use
|
||||||
///
|
///
|
||||||
/// ```edition2018
|
/// ```edition2021
|
||||||
/// use serde::ser::{Serialize, SerializeTupleStruct, Serializer};
|
/// use serde::ser::{Serialize, SerializeTupleStruct, Serializer};
|
||||||
///
|
///
|
||||||
/// struct Rgb(u8, u8, u8);
|
/// struct Rgb(u8, u8, u8);
|
||||||
@@ -1686,7 +1682,7 @@ pub trait SerializeTupleStruct {
|
|||||||
///
|
///
|
||||||
/// # Example use
|
/// # Example use
|
||||||
///
|
///
|
||||||
/// ```edition2018
|
/// ```edition2021
|
||||||
/// use serde::ser::{Serialize, SerializeTupleVariant, Serializer};
|
/// use serde::ser::{Serialize, SerializeTupleVariant, Serializer};
|
||||||
///
|
///
|
||||||
/// enum E {
|
/// enum E {
|
||||||
@@ -1744,7 +1740,7 @@ pub trait SerializeTupleVariant {
|
|||||||
///
|
///
|
||||||
/// # Example use
|
/// # Example use
|
||||||
///
|
///
|
||||||
/// ```edition2018
|
/// ```edition2021
|
||||||
/// # use std::marker::PhantomData;
|
/// # use std::marker::PhantomData;
|
||||||
/// #
|
/// #
|
||||||
/// # struct HashMap<K, V>(PhantomData<K>, PhantomData<V>);
|
/// # struct HashMap<K, V>(PhantomData<K>, PhantomData<V>);
|
||||||
@@ -1757,14 +1753,14 @@ pub trait SerializeTupleVariant {
|
|||||||
/// #
|
/// #
|
||||||
/// # impl<'a, K, V> IntoIterator for &'a HashMap<K, V> {
|
/// # impl<'a, K, V> IntoIterator for &'a HashMap<K, V> {
|
||||||
/// # type Item = (&'a K, &'a V);
|
/// # type Item = (&'a K, &'a V);
|
||||||
/// # type IntoIter = Box<Iterator<Item = (&'a K, &'a V)>>;
|
/// # type IntoIter = Box<dyn Iterator<Item = (&'a K, &'a V)>>;
|
||||||
/// #
|
/// #
|
||||||
/// # fn into_iter(self) -> Self::IntoIter {
|
/// # fn into_iter(self) -> Self::IntoIter {
|
||||||
/// # unimplemented!()
|
/// # unimplemented!()
|
||||||
/// # }
|
/// # }
|
||||||
/// # }
|
/// # }
|
||||||
/// #
|
/// #
|
||||||
/// use serde::ser::{Serialize, Serializer, SerializeMap};
|
/// use serde::ser::{Serialize, SerializeMap, Serializer};
|
||||||
///
|
///
|
||||||
/// impl<K, V> Serialize for HashMap<K, V>
|
/// impl<K, V> Serialize for HashMap<K, V>
|
||||||
/// where
|
/// where
|
||||||
@@ -1855,7 +1851,7 @@ pub trait SerializeMap {
|
|||||||
///
|
///
|
||||||
/// # Example use
|
/// # Example use
|
||||||
///
|
///
|
||||||
/// ```edition2018
|
/// ```edition2021
|
||||||
/// use serde::ser::{Serialize, SerializeStruct, Serializer};
|
/// use serde::ser::{Serialize, SerializeStruct, Serializer};
|
||||||
///
|
///
|
||||||
/// struct Rgb {
|
/// struct Rgb {
|
||||||
@@ -1915,7 +1911,7 @@ pub trait SerializeStruct {
|
|||||||
///
|
///
|
||||||
/// # Example use
|
/// # Example use
|
||||||
///
|
///
|
||||||
/// ```edition2018
|
/// ```edition2021
|
||||||
/// use serde::ser::{Serialize, SerializeStructVariant, Serializer};
|
/// use serde::ser::{Serialize, SerializeStructVariant, Serializer};
|
||||||
///
|
///
|
||||||
/// enum E {
|
/// enum E {
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ use lib::{Debug, Display};
|
|||||||
/// generally provide their error types with a `std::error::Error` impl
|
/// generally provide their error types with a `std::error::Error` impl
|
||||||
/// directly:
|
/// directly:
|
||||||
///
|
///
|
||||||
/// ```edition2018
|
/// ```edition2021
|
||||||
/// #[derive(Debug)]
|
/// #[derive(Debug)]
|
||||||
/// struct MySerError {...}
|
/// struct MySerError {...}
|
||||||
///
|
///
|
||||||
@@ -29,7 +29,7 @@ use lib::{Debug, Display};
|
|||||||
/// std = ["serde/std"]
|
/// std = ["serde/std"]
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// ```edition2018
|
/// ```edition2021
|
||||||
/// #[cfg(feature = "std")]
|
/// #[cfg(feature = "std")]
|
||||||
/// impl std::error::Error for MySerError {}
|
/// impl std::error::Error for MySerError {}
|
||||||
/// ```
|
/// ```
|
||||||
@@ -37,7 +37,7 @@ use lib::{Debug, Display};
|
|||||||
/// ... or else provide the std Error impl unconditionally via Serde's
|
/// ... or else provide the std Error impl unconditionally via Serde's
|
||||||
/// re-export:
|
/// re-export:
|
||||||
///
|
///
|
||||||
/// ```edition2018
|
/// ```edition2021
|
||||||
/// impl serde::ser::StdError for MySerError {}
|
/// impl serde::ser::StdError for MySerError {}
|
||||||
/// ```
|
/// ```
|
||||||
pub trait Error: Debug + Display {
|
pub trait Error: Debug + Display {
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "serde_derive"
|
name = "serde_derive"
|
||||||
version = "1.0.165" # remember to update html_root_url
|
version = "1.0.171" # 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>"]
|
||||||
categories = ["no-std"]
|
categories = ["no-std", "no-std::no-alloc"]
|
||||||
description = "Macros 1.1 implementation of #[derive(Serialize, Deserialize)]"
|
description = "Macros 1.1 implementation of #[derive(Serialize, Deserialize)]"
|
||||||
documentation = "https://serde.rs/derive.html"
|
documentation = "https://serde.rs/derive.html"
|
||||||
homepage = "https://serde.rs"
|
homepage = "https://serde.rs"
|
||||||
@@ -24,7 +24,7 @@ proc-macro = true
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
proc-macro2 = "1.0"
|
proc-macro2 = "1.0"
|
||||||
quote = "1.0"
|
quote = "1.0"
|
||||||
syn = "2.0.21"
|
syn = "2.0.25"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
serde = { version = "1.0", path = "../serde" }
|
serde = { version = "1.0", path = "../serde" }
|
||||||
|
|||||||
+192
-192
@@ -287,10 +287,10 @@ fn deserialize_body(cont: &Container, params: &Parameters) -> Fragment {
|
|||||||
match &cont.data {
|
match &cont.data {
|
||||||
Data::Enum(variants) => deserialize_enum(params, variants, &cont.attrs),
|
Data::Enum(variants) => deserialize_enum(params, variants, &cont.attrs),
|
||||||
Data::Struct(Style::Struct, fields) => {
|
Data::Struct(Style::Struct, fields) => {
|
||||||
deserialize_struct(None, params, fields, &cont.attrs, None, &Untagged::No)
|
deserialize_struct(params, fields, &cont.attrs, StructForm::Struct)
|
||||||
}
|
}
|
||||||
Data::Struct(Style::Tuple, fields) | Data::Struct(Style::Newtype, fields) => {
|
Data::Struct(Style::Tuple, fields) | Data::Struct(Style::Newtype, fields) => {
|
||||||
deserialize_tuple(None, params, fields, &cont.attrs, None)
|
deserialize_tuple(params, fields, &cont.attrs, TupleForm::Tuple)
|
||||||
}
|
}
|
||||||
Data::Struct(Style::Unit, _) => deserialize_unit_struct(params, &cont.attrs),
|
Data::Struct(Style::Unit, _) => deserialize_unit_struct(params, &cont.attrs),
|
||||||
}
|
}
|
||||||
@@ -410,16 +410,22 @@ fn deserialize_unit_struct(params: &Parameters, cattrs: &attr::Container) -> Fra
|
|||||||
let this_type = ¶ms.this_type;
|
let this_type = ¶ms.this_type;
|
||||||
let this_value = ¶ms.this_value;
|
let this_value = ¶ms.this_value;
|
||||||
let type_name = cattrs.name().deserialize_name();
|
let type_name = cattrs.name().deserialize_name();
|
||||||
|
let (de_impl_generics, de_ty_generics, ty_generics, where_clause) =
|
||||||
|
split_with_de_lifetime(params);
|
||||||
|
let delife = params.borrowed.de_lifetime();
|
||||||
|
|
||||||
let expecting = format!("unit struct {}", params.type_name());
|
let expecting = format!("unit struct {}", params.type_name());
|
||||||
let expecting = cattrs.expecting().unwrap_or(&expecting);
|
let expecting = cattrs.expecting().unwrap_or(&expecting);
|
||||||
|
|
||||||
quote_block! {
|
quote_block! {
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
struct __Visitor;
|
struct __Visitor #de_impl_generics #where_clause {
|
||||||
|
marker: _serde::__private::PhantomData<#this_type #ty_generics>,
|
||||||
|
lifetime: _serde::__private::PhantomData<&#delife ()>,
|
||||||
|
}
|
||||||
|
|
||||||
impl<'de> _serde::de::Visitor<'de> for __Visitor {
|
impl #de_impl_generics _serde::de::Visitor<#delife> for __Visitor #de_ty_generics #where_clause {
|
||||||
type Value = #this_type;
|
type Value = #this_type #ty_generics;
|
||||||
|
|
||||||
fn expecting(&self, __formatter: &mut _serde::__private::Formatter) -> _serde::__private::fmt::Result {
|
fn expecting(&self, __formatter: &mut _serde::__private::Formatter) -> _serde::__private::fmt::Result {
|
||||||
_serde::__private::Formatter::write_str(__formatter, #expecting)
|
_serde::__private::Formatter::write_str(__formatter, #expecting)
|
||||||
@@ -434,16 +440,31 @@ fn deserialize_unit_struct(params: &Parameters, cattrs: &attr::Container) -> Fra
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_serde::Deserializer::deserialize_unit_struct(__deserializer, #type_name, __Visitor)
|
_serde::Deserializer::deserialize_unit_struct(
|
||||||
|
__deserializer,
|
||||||
|
#type_name,
|
||||||
|
__Visitor {
|
||||||
|
marker: _serde::__private::PhantomData::<#this_type #ty_generics>,
|
||||||
|
lifetime: _serde::__private::PhantomData,
|
||||||
|
},
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum TupleForm<'a> {
|
||||||
|
Tuple,
|
||||||
|
/// Contains a variant name
|
||||||
|
ExternallyTagged(&'a syn::Ident),
|
||||||
|
/// Contains a variant name and an intermediate deserializer from which actual
|
||||||
|
/// deserialization will be performed
|
||||||
|
Untagged(&'a syn::Ident, TokenStream),
|
||||||
|
}
|
||||||
|
|
||||||
fn deserialize_tuple(
|
fn deserialize_tuple(
|
||||||
variant_ident: Option<&syn::Ident>,
|
|
||||||
params: &Parameters,
|
params: &Parameters,
|
||||||
fields: &[Field],
|
fields: &[Field],
|
||||||
cattrs: &attr::Container,
|
cattrs: &attr::Container,
|
||||||
deserializer: Option<TokenStream>,
|
form: TupleForm,
|
||||||
) -> Fragment {
|
) -> Fragment {
|
||||||
assert!(!cattrs.has_flatten());
|
assert!(!cattrs.has_flatten());
|
||||||
|
|
||||||
@@ -468,23 +489,27 @@ fn deserialize_tuple(
|
|||||||
quote!(#this_value)
|
quote!(#this_value)
|
||||||
};
|
};
|
||||||
|
|
||||||
let is_enum = variant_ident.is_some();
|
let type_path = match form {
|
||||||
let type_path = match variant_ident {
|
TupleForm::Tuple => construct,
|
||||||
Some(variant_ident) => quote!(#construct::#variant_ident),
|
TupleForm::ExternallyTagged(variant_ident) | TupleForm::Untagged(variant_ident, _) => {
|
||||||
None => construct,
|
quote!(#construct::#variant_ident)
|
||||||
|
}
|
||||||
};
|
};
|
||||||
let expecting = match variant_ident {
|
let expecting = match form {
|
||||||
Some(variant_ident) => format!("tuple variant {}::{}", params.type_name(), variant_ident),
|
TupleForm::Tuple => format!("tuple struct {}", params.type_name()),
|
||||||
None => format!("tuple struct {}", params.type_name()),
|
TupleForm::ExternallyTagged(variant_ident) | TupleForm::Untagged(variant_ident, _) => {
|
||||||
|
format!("tuple variant {}::{}", params.type_name(), variant_ident)
|
||||||
|
}
|
||||||
};
|
};
|
||||||
let expecting = cattrs.expecting().unwrap_or(&expecting);
|
let expecting = cattrs.expecting().unwrap_or(&expecting);
|
||||||
|
|
||||||
let nfields = fields.len();
|
let nfields = fields.len();
|
||||||
|
|
||||||
let visit_newtype_struct = if !is_enum && nfields == 1 {
|
let visit_newtype_struct = match form {
|
||||||
Some(deserialize_newtype_struct(&type_path, params, &fields[0]))
|
TupleForm::Tuple if nfields == 1 => {
|
||||||
} else {
|
Some(deserialize_newtype_struct(&type_path, params, &fields[0]))
|
||||||
None
|
}
|
||||||
|
_ => None,
|
||||||
};
|
};
|
||||||
|
|
||||||
let visit_seq = Stmts(deserialize_seq(
|
let visit_seq = Stmts(deserialize_seq(
|
||||||
@@ -497,16 +522,25 @@ fn deserialize_tuple(
|
|||||||
lifetime: _serde::__private::PhantomData,
|
lifetime: _serde::__private::PhantomData,
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let dispatch = if let Some(deserializer) = deserializer {
|
let dispatch = match form {
|
||||||
quote!(_serde::Deserializer::deserialize_tuple(#deserializer, #field_count, #visitor_expr))
|
TupleForm::Tuple if nfields == 1 => {
|
||||||
} else if is_enum {
|
let type_name = cattrs.name().deserialize_name();
|
||||||
quote!(_serde::de::VariantAccess::tuple_variant(__variant, #field_count, #visitor_expr))
|
quote! {
|
||||||
} else if nfields == 1 {
|
_serde::Deserializer::deserialize_newtype_struct(__deserializer, #type_name, #visitor_expr)
|
||||||
let type_name = cattrs.name().deserialize_name();
|
}
|
||||||
quote!(_serde::Deserializer::deserialize_newtype_struct(__deserializer, #type_name, #visitor_expr))
|
}
|
||||||
} else {
|
TupleForm::Tuple => {
|
||||||
let type_name = cattrs.name().deserialize_name();
|
let type_name = cattrs.name().deserialize_name();
|
||||||
quote!(_serde::Deserializer::deserialize_tuple_struct(__deserializer, #type_name, #field_count, #visitor_expr))
|
quote! {
|
||||||
|
_serde::Deserializer::deserialize_tuple_struct(__deserializer, #type_name, #field_count, #visitor_expr)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
TupleForm::ExternallyTagged(_) => quote! {
|
||||||
|
_serde::de::VariantAccess::tuple_variant(__variant, #field_count, #visitor_expr)
|
||||||
|
},
|
||||||
|
TupleForm::Untagged(_, deserializer) => quote! {
|
||||||
|
_serde::Deserializer::deserialize_tuple(#deserializer, #field_count, #visitor_expr)
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
let visitor_var = if field_count == 0 {
|
let visitor_var = if field_count == 0 {
|
||||||
@@ -901,21 +935,24 @@ fn deserialize_newtype_struct_in_place(params: &Parameters, field: &Field) -> To
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
enum Untagged {
|
enum StructForm<'a> {
|
||||||
Yes,
|
Struct,
|
||||||
No,
|
/// Contains a variant name
|
||||||
|
ExternallyTagged(&'a syn::Ident),
|
||||||
|
/// Contains a variant name and an intermediate deserializer from which actual
|
||||||
|
/// deserialization will be performed
|
||||||
|
InternallyTagged(&'a syn::Ident, TokenStream),
|
||||||
|
/// Contains a variant name and an intermediate deserializer from which actual
|
||||||
|
/// deserialization will be performed
|
||||||
|
Untagged(&'a syn::Ident, TokenStream),
|
||||||
}
|
}
|
||||||
|
|
||||||
fn deserialize_struct(
|
fn deserialize_struct(
|
||||||
variant_ident: Option<&syn::Ident>,
|
|
||||||
params: &Parameters,
|
params: &Parameters,
|
||||||
fields: &[Field],
|
fields: &[Field],
|
||||||
cattrs: &attr::Container,
|
cattrs: &attr::Container,
|
||||||
deserializer: Option<TokenStream>,
|
form: StructForm,
|
||||||
untagged: &Untagged,
|
|
||||||
) -> Fragment {
|
) -> Fragment {
|
||||||
let is_enum = variant_ident.is_some();
|
|
||||||
|
|
||||||
let this_type = ¶ms.this_type;
|
let this_type = ¶ms.this_type;
|
||||||
let this_value = ¶ms.this_value;
|
let this_value = ¶ms.this_value;
|
||||||
let (de_impl_generics, de_ty_generics, ty_generics, where_clause) =
|
let (de_impl_generics, de_ty_generics, ty_generics, where_clause) =
|
||||||
@@ -932,83 +969,74 @@ fn deserialize_struct(
|
|||||||
quote!(#this_value)
|
quote!(#this_value)
|
||||||
};
|
};
|
||||||
|
|
||||||
let type_path = match variant_ident {
|
let type_path = match form {
|
||||||
Some(variant_ident) => quote!(#construct::#variant_ident),
|
StructForm::Struct => construct,
|
||||||
None => construct,
|
StructForm::ExternallyTagged(variant_ident)
|
||||||
|
| StructForm::InternallyTagged(variant_ident, _)
|
||||||
|
| StructForm::Untagged(variant_ident, _) => quote!(#construct::#variant_ident),
|
||||||
};
|
};
|
||||||
let expecting = match variant_ident {
|
let expecting = match form {
|
||||||
Some(variant_ident) => format!("struct variant {}::{}", params.type_name(), variant_ident),
|
StructForm::Struct => format!("struct {}", params.type_name()),
|
||||||
None => format!("struct {}", params.type_name()),
|
StructForm::ExternallyTagged(variant_ident)
|
||||||
|
| StructForm::InternallyTagged(variant_ident, _)
|
||||||
|
| StructForm::Untagged(variant_ident, _) => {
|
||||||
|
format!("struct variant {}::{}", params.type_name(), variant_ident)
|
||||||
|
}
|
||||||
};
|
};
|
||||||
let expecting = cattrs.expecting().unwrap_or(&expecting);
|
let expecting = cattrs.expecting().unwrap_or(&expecting);
|
||||||
|
|
||||||
let visit_seq = Stmts(deserialize_seq(
|
let field_names_idents: Vec<_> = fields
|
||||||
&type_path, params, fields, true, cattrs, expecting,
|
.iter()
|
||||||
|
.enumerate()
|
||||||
|
// Skip fields that shouldn't be deserialized or that were flattened,
|
||||||
|
// so they don't appear in the storage in their literal form
|
||||||
|
.filter(|&(_, field)| !field.attrs.skip_deserializing() && !field.attrs.flatten())
|
||||||
|
.map(|(i, field)| {
|
||||||
|
(
|
||||||
|
field.attrs.name().deserialize_name(),
|
||||||
|
field_i(i),
|
||||||
|
field.attrs.aliases(),
|
||||||
|
)
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
let field_visitor = Stmts(deserialize_generated_identifier(
|
||||||
|
&field_names_idents,
|
||||||
|
cattrs,
|
||||||
|
false,
|
||||||
|
None,
|
||||||
));
|
));
|
||||||
|
|
||||||
let (field_visitor, fields_stmt, visit_map) = if cattrs.has_flatten() {
|
|
||||||
deserialize_struct_as_map_visitor(&type_path, params, fields, cattrs)
|
|
||||||
} else {
|
|
||||||
deserialize_struct_as_struct_visitor(&type_path, params, fields, cattrs)
|
|
||||||
};
|
|
||||||
let field_visitor = Stmts(field_visitor);
|
|
||||||
let fields_stmt = fields_stmt.map(Stmts);
|
|
||||||
let visit_map = Stmts(visit_map);
|
|
||||||
|
|
||||||
let visitor_expr = quote! {
|
|
||||||
__Visitor {
|
|
||||||
marker: _serde::__private::PhantomData::<#this_type #ty_generics>,
|
|
||||||
lifetime: _serde::__private::PhantomData,
|
|
||||||
}
|
|
||||||
};
|
|
||||||
let need_seed = deserializer.is_none();
|
|
||||||
let dispatch = if let Some(deserializer) = deserializer {
|
|
||||||
quote! {
|
|
||||||
_serde::Deserializer::deserialize_any(#deserializer, #visitor_expr)
|
|
||||||
}
|
|
||||||
} else if is_enum && cattrs.has_flatten() {
|
|
||||||
quote! {
|
|
||||||
_serde::de::VariantAccess::newtype_variant_seed(__variant, #visitor_expr)
|
|
||||||
}
|
|
||||||
} else if is_enum {
|
|
||||||
quote! {
|
|
||||||
_serde::de::VariantAccess::struct_variant(__variant, FIELDS, #visitor_expr)
|
|
||||||
}
|
|
||||||
} else if cattrs.has_flatten() {
|
|
||||||
quote! {
|
|
||||||
_serde::Deserializer::deserialize_map(__deserializer, #visitor_expr)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
let type_name = cattrs.name().deserialize_name();
|
|
||||||
quote! {
|
|
||||||
_serde::Deserializer::deserialize_struct(__deserializer, #type_name, FIELDS, #visitor_expr)
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
let all_skipped = fields.iter().all(|field| field.attrs.skip_deserializing());
|
|
||||||
let visitor_var = if all_skipped {
|
|
||||||
quote!(_)
|
|
||||||
} else {
|
|
||||||
quote!(mut __seq)
|
|
||||||
};
|
|
||||||
|
|
||||||
// untagged struct variants do not get a visit_seq method. The same applies to
|
// untagged struct variants do not get a visit_seq method. The same applies to
|
||||||
// structs that only have a map representation.
|
// structs that only have a map representation.
|
||||||
let visit_seq = match *untagged {
|
let visit_seq = match form {
|
||||||
Untagged::No if !cattrs.has_flatten() => Some(quote! {
|
StructForm::Untagged(..) => None,
|
||||||
#[inline]
|
_ if cattrs.has_flatten() => None,
|
||||||
fn visit_seq<__A>(self, #visitor_var: __A) -> _serde::__private::Result<Self::Value, __A::Error>
|
_ => {
|
||||||
where
|
let mut_seq = if field_names_idents.is_empty() {
|
||||||
__A: _serde::de::SeqAccess<#delife>,
|
quote!(_)
|
||||||
{
|
} else {
|
||||||
#visit_seq
|
quote!(mut __seq)
|
||||||
}
|
};
|
||||||
}),
|
|
||||||
_ => None,
|
|
||||||
};
|
|
||||||
|
|
||||||
let visitor_seed = if need_seed && is_enum && cattrs.has_flatten() {
|
let visit_seq = Stmts(deserialize_seq(
|
||||||
Some(quote! {
|
&type_path, params, fields, true, cattrs, expecting,
|
||||||
|
));
|
||||||
|
|
||||||
|
Some(quote! {
|
||||||
|
#[inline]
|
||||||
|
fn visit_seq<__A>(self, #mut_seq: __A) -> _serde::__private::Result<Self::Value, __A::Error>
|
||||||
|
where
|
||||||
|
__A: _serde::de::SeqAccess<#delife>,
|
||||||
|
{
|
||||||
|
#visit_seq
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
};
|
||||||
|
let visit_map = Stmts(deserialize_map(&type_path, params, fields, cattrs));
|
||||||
|
|
||||||
|
let visitor_seed = match form {
|
||||||
|
StructForm::ExternallyTagged(..) if cattrs.has_flatten() => Some(quote! {
|
||||||
impl #de_impl_generics _serde::de::DeserializeSeed<#delife> for __Visitor #de_ty_generics #where_clause {
|
impl #de_impl_generics _serde::de::DeserializeSeed<#delife> for __Visitor #de_ty_generics #where_clause {
|
||||||
type Value = #this_type #ty_generics;
|
type Value = #this_type #ty_generics;
|
||||||
|
|
||||||
@@ -1019,9 +1047,51 @@ fn deserialize_struct(
|
|||||||
_serde::Deserializer::deserialize_map(__deserializer, self)
|
_serde::Deserializer::deserialize_map(__deserializer, self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
}),
|
||||||
} else {
|
_ => None,
|
||||||
|
};
|
||||||
|
|
||||||
|
let fields_stmt = if cattrs.has_flatten() {
|
||||||
None
|
None
|
||||||
|
} else {
|
||||||
|
let field_names = field_names_idents
|
||||||
|
.iter()
|
||||||
|
.flat_map(|(_, _, aliases)| aliases);
|
||||||
|
|
||||||
|
Some(quote! {
|
||||||
|
#[doc(hidden)]
|
||||||
|
const FIELDS: &'static [&'static str] = &[ #(#field_names),* ];
|
||||||
|
})
|
||||||
|
};
|
||||||
|
|
||||||
|
let visitor_expr = quote! {
|
||||||
|
__Visitor {
|
||||||
|
marker: _serde::__private::PhantomData::<#this_type #ty_generics>,
|
||||||
|
lifetime: _serde::__private::PhantomData,
|
||||||
|
}
|
||||||
|
};
|
||||||
|
let dispatch = match form {
|
||||||
|
StructForm::Struct if cattrs.has_flatten() => quote! {
|
||||||
|
_serde::Deserializer::deserialize_map(__deserializer, #visitor_expr)
|
||||||
|
},
|
||||||
|
StructForm::Struct => {
|
||||||
|
let type_name = cattrs.name().deserialize_name();
|
||||||
|
quote! {
|
||||||
|
_serde::Deserializer::deserialize_struct(__deserializer, #type_name, FIELDS, #visitor_expr)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
StructForm::ExternallyTagged(_) if cattrs.has_flatten() => quote! {
|
||||||
|
_serde::de::VariantAccess::newtype_variant_seed(__variant, #visitor_expr)
|
||||||
|
},
|
||||||
|
StructForm::ExternallyTagged(_) => quote! {
|
||||||
|
_serde::de::VariantAccess::struct_variant(__variant, FIELDS, #visitor_expr)
|
||||||
|
},
|
||||||
|
StructForm::InternallyTagged(_, deserializer) => quote! {
|
||||||
|
_serde::Deserializer::deserialize_any(#deserializer, #visitor_expr)
|
||||||
|
},
|
||||||
|
StructForm::Untagged(_, deserializer) => quote! {
|
||||||
|
_serde::Deserializer::deserialize_any(#deserializer, #visitor_expr)
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
quote_block! {
|
quote_block! {
|
||||||
@@ -1356,9 +1426,7 @@ fn deserialize_internally_tagged_enum(
|
|||||||
params,
|
params,
|
||||||
variant,
|
variant,
|
||||||
cattrs,
|
cattrs,
|
||||||
quote! {
|
quote!(__deserializer),
|
||||||
_serde::__private::de::ContentDeserializer::<__D::Error>::new(__tagged.content)
|
|
||||||
},
|
|
||||||
));
|
));
|
||||||
|
|
||||||
quote! {
|
quote! {
|
||||||
@@ -1374,11 +1442,12 @@ fn deserialize_internally_tagged_enum(
|
|||||||
|
|
||||||
#variants_stmt
|
#variants_stmt
|
||||||
|
|
||||||
let __tagged = try!(_serde::Deserializer::deserialize_any(
|
let (__tag, __content) = try!(_serde::Deserializer::deserialize_any(
|
||||||
__deserializer,
|
__deserializer,
|
||||||
_serde::__private::de::TaggedContentVisitor::<__Field>::new(#tag, #expecting)));
|
_serde::__private::de::TaggedContentVisitor::<__Field>::new(#tag, #expecting)));
|
||||||
|
let __deserializer = _serde::__private::de::ContentDeserializer::<__D::Error>::new(__content);
|
||||||
|
|
||||||
match __tagged.tag {
|
match __tag {
|
||||||
#(#variant_arms)*
|
#(#variant_arms)*
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1769,16 +1838,17 @@ fn deserialize_externally_tagged_variant(
|
|||||||
&variant.fields[0],
|
&variant.fields[0],
|
||||||
cattrs,
|
cattrs,
|
||||||
),
|
),
|
||||||
Style::Tuple => {
|
Style::Tuple => deserialize_tuple(
|
||||||
deserialize_tuple(Some(variant_ident), params, &variant.fields, cattrs, None)
|
|
||||||
}
|
|
||||||
Style::Struct => deserialize_struct(
|
|
||||||
Some(variant_ident),
|
|
||||||
params,
|
params,
|
||||||
&variant.fields,
|
&variant.fields,
|
||||||
cattrs,
|
cattrs,
|
||||||
None,
|
TupleForm::ExternallyTagged(variant_ident),
|
||||||
&Untagged::No,
|
),
|
||||||
|
Style::Struct => deserialize_struct(
|
||||||
|
params,
|
||||||
|
&variant.fields,
|
||||||
|
cattrs,
|
||||||
|
StructForm::ExternallyTagged(variant_ident),
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1818,12 +1888,10 @@ fn deserialize_internally_tagged_variant(
|
|||||||
&deserializer,
|
&deserializer,
|
||||||
),
|
),
|
||||||
Style::Struct => deserialize_struct(
|
Style::Struct => deserialize_struct(
|
||||||
Some(variant_ident),
|
|
||||||
params,
|
params,
|
||||||
&variant.fields,
|
&variant.fields,
|
||||||
cattrs,
|
cattrs,
|
||||||
Some(deserializer),
|
StructForm::InternallyTagged(variant_ident, deserializer),
|
||||||
&Untagged::No,
|
|
||||||
),
|
),
|
||||||
Style::Tuple => unreachable!("checked in serde_derive_internals"),
|
Style::Tuple => unreachable!("checked in serde_derive_internals"),
|
||||||
}
|
}
|
||||||
@@ -1870,19 +1938,16 @@ fn deserialize_untagged_variant(
|
|||||||
&deserializer,
|
&deserializer,
|
||||||
),
|
),
|
||||||
Style::Tuple => deserialize_tuple(
|
Style::Tuple => deserialize_tuple(
|
||||||
Some(variant_ident),
|
|
||||||
params,
|
params,
|
||||||
&variant.fields,
|
&variant.fields,
|
||||||
cattrs,
|
cattrs,
|
||||||
Some(deserializer),
|
TupleForm::Untagged(variant_ident, deserializer),
|
||||||
),
|
),
|
||||||
Style::Struct => deserialize_struct(
|
Style::Struct => deserialize_struct(
|
||||||
Some(variant_ident),
|
|
||||||
params,
|
params,
|
||||||
&variant.fields,
|
&variant.fields,
|
||||||
cattrs,
|
cattrs,
|
||||||
Some(deserializer),
|
StructForm::Untagged(variant_ident, deserializer),
|
||||||
&Untagged::Yes,
|
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2423,71 +2488,6 @@ fn deserialize_identifier(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn deserialize_struct_as_struct_visitor(
|
|
||||||
struct_path: &TokenStream,
|
|
||||||
params: &Parameters,
|
|
||||||
fields: &[Field],
|
|
||||||
cattrs: &attr::Container,
|
|
||||||
) -> (Fragment, Option<Fragment>, Fragment) {
|
|
||||||
assert!(!cattrs.has_flatten());
|
|
||||||
|
|
||||||
let field_names_idents: Vec<_> = fields
|
|
||||||
.iter()
|
|
||||||
.enumerate()
|
|
||||||
.filter(|&(_, field)| !field.attrs.skip_deserializing())
|
|
||||||
.map(|(i, field)| {
|
|
||||||
(
|
|
||||||
field.attrs.name().deserialize_name(),
|
|
||||||
field_i(i),
|
|
||||||
field.attrs.aliases(),
|
|
||||||
)
|
|
||||||
})
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
let fields_stmt = {
|
|
||||||
let field_names = field_names_idents
|
|
||||||
.iter()
|
|
||||||
.flat_map(|(_, _, aliases)| aliases);
|
|
||||||
|
|
||||||
quote_block! {
|
|
||||||
#[doc(hidden)]
|
|
||||||
const FIELDS: &'static [&'static str] = &[ #(#field_names),* ];
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
let field_visitor = deserialize_generated_identifier(&field_names_idents, cattrs, false, None);
|
|
||||||
|
|
||||||
let visit_map = deserialize_map(struct_path, params, fields, cattrs);
|
|
||||||
|
|
||||||
(field_visitor, Some(fields_stmt), visit_map)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn deserialize_struct_as_map_visitor(
|
|
||||||
struct_path: &TokenStream,
|
|
||||||
params: &Parameters,
|
|
||||||
fields: &[Field],
|
|
||||||
cattrs: &attr::Container,
|
|
||||||
) -> (Fragment, Option<Fragment>, Fragment) {
|
|
||||||
let field_names_idents: Vec<_> = fields
|
|
||||||
.iter()
|
|
||||||
.enumerate()
|
|
||||||
.filter(|&(_, field)| !field.attrs.skip_deserializing() && !field.attrs.flatten())
|
|
||||||
.map(|(i, field)| {
|
|
||||||
(
|
|
||||||
field.attrs.name().deserialize_name(),
|
|
||||||
field_i(i),
|
|
||||||
field.attrs.aliases(),
|
|
||||||
)
|
|
||||||
})
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
let field_visitor = deserialize_generated_identifier(&field_names_idents, cattrs, false, None);
|
|
||||||
|
|
||||||
let visit_map = deserialize_map(struct_path, params, fields, cattrs);
|
|
||||||
|
|
||||||
(field_visitor, None, visit_map)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn deserialize_map(
|
fn deserialize_map(
|
||||||
struct_path: &TokenStream,
|
struct_path: &TokenStream,
|
||||||
params: &Parameters,
|
params: &Parameters,
|
||||||
|
|||||||
@@ -1418,6 +1418,13 @@ fn get_lit_str2(
|
|||||||
..
|
..
|
||||||
}) = value
|
}) = value
|
||||||
{
|
{
|
||||||
|
let suffix = lit.suffix();
|
||||||
|
if !suffix.is_empty() {
|
||||||
|
cx.error_spanned_by(
|
||||||
|
lit,
|
||||||
|
format!("unexpected suffix `{}` on string literal", suffix),
|
||||||
|
);
|
||||||
|
}
|
||||||
Ok(Some(lit.clone()))
|
Ok(Some(lit.clone()))
|
||||||
} else {
|
} else {
|
||||||
cx.error_spanned_by(
|
cx.error_spanned_by(
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
//! This crate provides Serde's two derive macros.
|
//! This crate provides Serde's two derive macros.
|
||||||
//!
|
//!
|
||||||
//! ```edition2018
|
//! ```edition2021
|
||||||
//! # use serde_derive::{Serialize, Deserialize};
|
//! # use serde_derive::{Deserialize, Serialize};
|
||||||
//! #
|
//! #
|
||||||
//! #[derive(Serialize, Deserialize)]
|
//! #[derive(Serialize, Deserialize)]
|
||||||
//! # struct S;
|
//! # struct S;
|
||||||
@@ -13,7 +13,7 @@
|
|||||||
//!
|
//!
|
||||||
//! [https://serde.rs/derive.html]: https://serde.rs/derive.html
|
//! [https://serde.rs/derive.html]: https://serde.rs/derive.html
|
||||||
|
|
||||||
#![doc(html_root_url = "https://docs.rs/serde_derive/1.0.165")]
|
#![doc(html_root_url = "https://docs.rs/serde_derive/1.0.171")]
|
||||||
#![allow(unknown_lints, bare_trait_objects)]
|
#![allow(unknown_lints, bare_trait_objects)]
|
||||||
// Ignored clippy lints
|
// Ignored clippy lints
|
||||||
#![allow(
|
#![allow(
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ path = "lib.rs"
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
proc-macro2 = "1.0"
|
proc-macro2 = "1.0"
|
||||||
quote = "1.0"
|
quote = "1.0"
|
||||||
syn = { version = "2.0.21", default-features = false, features = ["derive", "parsing", "printing", "clone-impls"] }
|
syn = { version = "2.0.25", default-features = false, features = ["clone-impls", "derive", "parsing", "printing"] }
|
||||||
|
|
||||||
[package.metadata.docs.rs]
|
[package.metadata.docs.rs]
|
||||||
targets = ["x86_64-unknown-linux-gnu"]
|
targets = ["x86_64-unknown-linux-gnu"]
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "serde_test"
|
name = "serde_test"
|
||||||
version = "1.0.165" # remember to update html_root_url
|
version = "1.0.171" # 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>"]
|
||||||
build = "build.rs"
|
build = "build.rs"
|
||||||
categories = ["development-tools::testing"]
|
categories = ["development-tools::testing"]
|
||||||
@@ -18,7 +18,7 @@ rust-version = "1.19"
|
|||||||
serde = { version = "1.0.60", path = "../serde" }
|
serde = { version = "1.0.60", path = "../serde" }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
serde = { version = "1.0", path = "../serde" }
|
serde = { version = "1.0", path = "../serde", features = ["rc"] }
|
||||||
serde_derive = { version = "1.0", path = "../serde_derive" }
|
serde_derive = { version = "1.0", path = "../serde_derive" }
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
|
|||||||
+54
-40
@@ -8,8 +8,8 @@ use std::fmt::Debug;
|
|||||||
|
|
||||||
/// Runs both `assert_ser_tokens` and `assert_de_tokens`.
|
/// Runs both `assert_ser_tokens` and `assert_de_tokens`.
|
||||||
///
|
///
|
||||||
/// ```edition2018
|
/// ```edition2021
|
||||||
/// # use serde::{Serialize, Deserialize};
|
/// # use serde_derive::{Deserialize, Serialize};
|
||||||
/// # use serde_test::{assert_tokens, Token};
|
/// # use serde_test::{assert_tokens, Token};
|
||||||
/// #
|
/// #
|
||||||
/// #[derive(Serialize, Deserialize, PartialEq, Debug)]
|
/// #[derive(Serialize, Deserialize, PartialEq, Debug)]
|
||||||
@@ -19,14 +19,17 @@ use std::fmt::Debug;
|
|||||||
/// }
|
/// }
|
||||||
///
|
///
|
||||||
/// let s = S { a: 0, b: 0 };
|
/// let s = S { a: 0, b: 0 };
|
||||||
/// assert_tokens(&s, &[
|
/// assert_tokens(
|
||||||
/// Token::Struct { name: "S", len: 2 },
|
/// &s,
|
||||||
/// Token::Str("a"),
|
/// &[
|
||||||
/// Token::U8(0),
|
/// Token::Struct { name: "S", len: 2 },
|
||||||
/// Token::Str("b"),
|
/// Token::Str("a"),
|
||||||
/// Token::U8(0),
|
/// Token::U8(0),
|
||||||
/// Token::StructEnd,
|
/// Token::Str("b"),
|
||||||
/// ]);
|
/// Token::U8(0),
|
||||||
|
/// Token::StructEnd,
|
||||||
|
/// ],
|
||||||
|
/// );
|
||||||
/// ```
|
/// ```
|
||||||
#[cfg_attr(not(no_track_caller), track_caller)]
|
#[cfg_attr(not(no_track_caller), track_caller)]
|
||||||
pub fn assert_tokens<'de, T>(value: &T, tokens: &'de [Token])
|
pub fn assert_tokens<'de, T>(value: &T, tokens: &'de [Token])
|
||||||
@@ -39,8 +42,8 @@ where
|
|||||||
|
|
||||||
/// Asserts that `value` serializes to the given `tokens`.
|
/// Asserts that `value` serializes to the given `tokens`.
|
||||||
///
|
///
|
||||||
/// ```edition2018
|
/// ```edition2021
|
||||||
/// # use serde::{Serialize, Deserialize};
|
/// # use serde_derive::{Deserialize, Serialize};
|
||||||
/// # use serde_test::{assert_ser_tokens, Token};
|
/// # use serde_test::{assert_ser_tokens, Token};
|
||||||
/// #
|
/// #
|
||||||
/// #[derive(Serialize, Deserialize, PartialEq, Debug)]
|
/// #[derive(Serialize, Deserialize, PartialEq, Debug)]
|
||||||
@@ -50,14 +53,17 @@ where
|
|||||||
/// }
|
/// }
|
||||||
///
|
///
|
||||||
/// let s = S { a: 0, b: 0 };
|
/// let s = S { a: 0, b: 0 };
|
||||||
/// assert_ser_tokens(&s, &[
|
/// assert_ser_tokens(
|
||||||
/// Token::Struct { name: "S", len: 2 },
|
/// &s,
|
||||||
/// Token::Str("a"),
|
/// &[
|
||||||
/// Token::U8(0),
|
/// Token::Struct { name: "S", len: 2 },
|
||||||
/// Token::Str("b"),
|
/// Token::Str("a"),
|
||||||
/// Token::U8(0),
|
/// Token::U8(0),
|
||||||
/// Token::StructEnd,
|
/// Token::Str("b"),
|
||||||
/// ]);
|
/// Token::U8(0),
|
||||||
|
/// Token::StructEnd,
|
||||||
|
/// ],
|
||||||
|
/// );
|
||||||
/// ```
|
/// ```
|
||||||
#[cfg_attr(not(no_track_caller), track_caller)]
|
#[cfg_attr(not(no_track_caller), track_caller)]
|
||||||
pub fn assert_ser_tokens<T: ?Sized>(value: &T, tokens: &[Token])
|
pub fn assert_ser_tokens<T: ?Sized>(value: &T, tokens: &[Token])
|
||||||
@@ -78,23 +84,24 @@ 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`.
|
||||||
///
|
///
|
||||||
/// ```edition2018
|
/// ```edition2021
|
||||||
|
/// use serde_derive::Serialize;
|
||||||
|
/// use serde_test::{assert_ser_tokens_error, Token};
|
||||||
/// 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};
|
|
||||||
///
|
|
||||||
/// #[derive(Serialize)]
|
/// #[derive(Serialize)]
|
||||||
/// struct Example {
|
/// struct Example {
|
||||||
/// lock: Arc<Mutex<u32>>,
|
/// lock: Arc<Mutex<u32>>,
|
||||||
/// }
|
/// }
|
||||||
///
|
///
|
||||||
/// fn main() {
|
/// fn main() {
|
||||||
/// let example = Example { lock: Arc::new(Mutex::new(0)) };
|
/// let example = Example {
|
||||||
|
/// lock: Arc::new(Mutex::new(0)),
|
||||||
|
/// };
|
||||||
/// let lock = example.lock.clone();
|
/// let lock = example.lock.clone();
|
||||||
///
|
///
|
||||||
/// let _ = thread::spawn(move || {
|
/// let thread = 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();
|
||||||
@@ -102,10 +109,14 @@ where
|
|||||||
/// // 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();
|
/// });
|
||||||
|
/// thread.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";
|
||||||
@@ -130,8 +141,8 @@ where
|
|||||||
|
|
||||||
/// Asserts that the given `tokens` deserialize into `value`.
|
/// Asserts that the given `tokens` deserialize into `value`.
|
||||||
///
|
///
|
||||||
/// ```edition2018
|
/// ```edition2021
|
||||||
/// # use serde::{Serialize, Deserialize};
|
/// # use serde_derive::{Deserialize, Serialize};
|
||||||
/// # use serde_test::{assert_de_tokens, Token};
|
/// # use serde_test::{assert_de_tokens, Token};
|
||||||
/// #
|
/// #
|
||||||
/// #[derive(Serialize, Deserialize, PartialEq, Debug)]
|
/// #[derive(Serialize, Deserialize, PartialEq, Debug)]
|
||||||
@@ -141,14 +152,17 @@ where
|
|||||||
/// }
|
/// }
|
||||||
///
|
///
|
||||||
/// let s = S { a: 0, b: 0 };
|
/// let s = S { a: 0, b: 0 };
|
||||||
/// assert_de_tokens(&s, &[
|
/// assert_de_tokens(
|
||||||
/// Token::Struct { name: "S", len: 2 },
|
/// &s,
|
||||||
/// Token::Str("a"),
|
/// &[
|
||||||
/// Token::U8(0),
|
/// Token::Struct { name: "S", len: 2 },
|
||||||
/// Token::Str("b"),
|
/// Token::Str("a"),
|
||||||
/// Token::U8(0),
|
/// Token::U8(0),
|
||||||
/// Token::StructEnd,
|
/// Token::Str("b"),
|
||||||
/// ]);
|
/// Token::U8(0),
|
||||||
|
/// Token::StructEnd,
|
||||||
|
/// ],
|
||||||
|
/// );
|
||||||
/// ```
|
/// ```
|
||||||
#[cfg_attr(not(no_track_caller), track_caller)]
|
#[cfg_attr(not(no_track_caller), track_caller)]
|
||||||
pub fn assert_de_tokens<'de, T>(value: &T, tokens: &'de [Token])
|
pub fn assert_de_tokens<'de, T>(value: &T, tokens: &'de [Token])
|
||||||
@@ -184,8 +198,8 @@ where
|
|||||||
|
|
||||||
/// Asserts that the given `tokens` yield `error` when deserializing.
|
/// Asserts that the given `tokens` yield `error` when deserializing.
|
||||||
///
|
///
|
||||||
/// ```edition2018
|
/// ```edition2021
|
||||||
/// # use serde::{Serialize, Deserialize};
|
/// # use serde_derive::{Deserialize, Serialize};
|
||||||
/// # use serde_test::{assert_de_tokens_error, Token};
|
/// # use serde_test::{assert_de_tokens_error, Token};
|
||||||
/// #
|
/// #
|
||||||
/// #[derive(Serialize, Deserialize, PartialEq, Debug)]
|
/// #[derive(Serialize, Deserialize, PartialEq, Debug)]
|
||||||
|
|||||||
@@ -14,7 +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
|
/// ```edition2021
|
||||||
/// 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};
|
||||||
///
|
///
|
||||||
|
|||||||
+23
-19
@@ -20,11 +20,11 @@
|
|||||||
//!
|
//!
|
||||||
//! [`linked-hash-map`]: https://github.com/contain-rs/linked-hash-map
|
//! [`linked-hash-map`]: https://github.com/contain-rs/linked-hash-map
|
||||||
//!
|
//!
|
||||||
//! ```edition2018
|
//! ```edition2021
|
||||||
//! # const IGNORE: &str = stringify! {
|
//! # const IGNORE: &str = stringify! {
|
||||||
//! use linked_hash_map::LinkedHashMap;
|
//! use linked_hash_map::LinkedHashMap;
|
||||||
//! # };
|
//! # };
|
||||||
//! use serde_test::{Token, assert_tokens};
|
//! use serde_test::{assert_tokens, Token};
|
||||||
//!
|
//!
|
||||||
//! # use std::fmt;
|
//! # use std::fmt;
|
||||||
//! # use std::marker::PhantomData;
|
//! # use std::marker::PhantomData;
|
||||||
@@ -106,10 +106,13 @@
|
|||||||
//! fn test_ser_de_empty() {
|
//! fn test_ser_de_empty() {
|
||||||
//! let map = LinkedHashMap::<char, u32>::new();
|
//! let map = LinkedHashMap::<char, u32>::new();
|
||||||
//!
|
//!
|
||||||
//! assert_tokens(&map, &[
|
//! assert_tokens(
|
||||||
//! Token::Map { len: Some(0) },
|
//! &map,
|
||||||
//! Token::MapEnd,
|
//! &[
|
||||||
//! ]);
|
//! Token::Map { len: Some(0) },
|
||||||
|
//! Token::MapEnd,
|
||||||
|
//! ],
|
||||||
|
//! );
|
||||||
//! }
|
//! }
|
||||||
//!
|
//!
|
||||||
//! #[test]
|
//! #[test]
|
||||||
@@ -120,18 +123,19 @@
|
|||||||
//! map.insert('a', 10);
|
//! map.insert('a', 10);
|
||||||
//! map.insert('c', 30);
|
//! map.insert('c', 30);
|
||||||
//!
|
//!
|
||||||
//! assert_tokens(&map, &[
|
//! assert_tokens(
|
||||||
//! Token::Map { len: Some(3) },
|
//! &map,
|
||||||
//! Token::Char('b'),
|
//! &[
|
||||||
//! Token::I32(20),
|
//! Token::Map { len: Some(3) },
|
||||||
//!
|
//! Token::Char('b'),
|
||||||
//! Token::Char('a'),
|
//! Token::I32(20),
|
||||||
//! Token::I32(10),
|
//! Token::Char('a'),
|
||||||
//!
|
//! Token::I32(10),
|
||||||
//! Token::Char('c'),
|
//! Token::Char('c'),
|
||||||
//! Token::I32(30),
|
//! Token::I32(30),
|
||||||
//! Token::MapEnd,
|
//! Token::MapEnd,
|
||||||
//! ]);
|
//! ],
|
||||||
|
//! );
|
||||||
//! }
|
//! }
|
||||||
//! #
|
//! #
|
||||||
//! # fn main() {
|
//! # fn main() {
|
||||||
@@ -140,7 +144,7 @@
|
|||||||
//! # }
|
//! # }
|
||||||
//! ```
|
//! ```
|
||||||
|
|
||||||
#![doc(html_root_url = "https://docs.rs/serde_test/1.0.165")]
|
#![doc(html_root_url = "https://docs.rs/serde_test/1.0.171")]
|
||||||
#![cfg_attr(feature = "cargo-clippy", allow(renamed_and_removed_lints))]
|
#![cfg_attr(feature = "cargo-clippy", allow(renamed_and_removed_lints))]
|
||||||
// Ignored clippy lints
|
// Ignored clippy lints
|
||||||
#![cfg_attr(feature = "cargo-clippy", allow(float_cmp, needless_doctest_main))]
|
#![cfg_attr(feature = "cargo-clippy", allow(float_cmp, needless_doctest_main))]
|
||||||
|
|||||||
+167
-125
@@ -4,7 +4,7 @@ use std::fmt::{self, Debug, Display};
|
|||||||
pub enum Token {
|
pub enum Token {
|
||||||
/// A serialized `bool`.
|
/// A serialized `bool`.
|
||||||
///
|
///
|
||||||
/// ```edition2018
|
/// ```edition2021
|
||||||
/// # 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`.
|
||||||
///
|
///
|
||||||
/// ```edition2018
|
/// ```edition2021
|
||||||
/// # 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`.
|
||||||
///
|
///
|
||||||
/// ```edition2018
|
/// ```edition2021
|
||||||
/// # 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`.
|
||||||
///
|
///
|
||||||
/// ```edition2018
|
/// ```edition2021
|
||||||
/// # 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`.
|
||||||
///
|
///
|
||||||
/// ```edition2018
|
/// ```edition2021
|
||||||
/// # 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`.
|
||||||
///
|
///
|
||||||
/// ```edition2018
|
/// ```edition2021
|
||||||
/// # 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`.
|
||||||
///
|
///
|
||||||
/// ```edition2018
|
/// ```edition2021
|
||||||
/// # 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`.
|
||||||
///
|
///
|
||||||
/// ```edition2018
|
/// ```edition2021
|
||||||
/// # 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`.
|
||||||
///
|
///
|
||||||
/// ```edition2018
|
/// ```edition2021
|
||||||
/// # 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`.
|
||||||
///
|
///
|
||||||
/// ```edition2018
|
/// ```edition2021
|
||||||
/// # 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`.
|
||||||
///
|
///
|
||||||
/// ```edition2018
|
/// ```edition2021
|
||||||
/// # 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`.
|
||||||
///
|
///
|
||||||
/// ```edition2018
|
/// ```edition2021
|
||||||
/// # 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`.
|
||||||
///
|
///
|
||||||
/// ```edition2018
|
/// ```edition2021
|
||||||
/// # 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`.
|
||||||
///
|
///
|
||||||
/// ```edition2018
|
/// ```edition2021
|
||||||
/// # 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`.
|
||||||
///
|
///
|
||||||
/// ```edition2018
|
/// ```edition2021
|
||||||
/// # 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.
|
||||||
///
|
///
|
||||||
/// ```edition2018
|
/// ```edition2021
|
||||||
/// # use serde_test::{assert_tokens, Token};
|
/// # use serde_test::{assert_tokens, Token};
|
||||||
/// #
|
/// #
|
||||||
/// let opt = None::<char>;
|
/// let opt = None::<char>;
|
||||||
@@ -163,20 +163,17 @@ pub enum Token {
|
|||||||
///
|
///
|
||||||
/// The tokens of the value follow after this header.
|
/// The tokens of the value follow after this header.
|
||||||
///
|
///
|
||||||
/// ```edition2018
|
/// ```edition2021
|
||||||
/// # use serde_test::{assert_tokens, Token};
|
/// # use serde_test::{assert_tokens, Token};
|
||||||
/// #
|
/// #
|
||||||
/// let opt = Some('c');
|
/// let opt = Some('c');
|
||||||
/// assert_tokens(&opt, &[
|
/// assert_tokens(&opt, &[Token::Some, Token::Char('c')]);
|
||||||
/// Token::Some,
|
|
||||||
/// Token::Char('c'),
|
|
||||||
/// ]);
|
|
||||||
/// ```
|
/// ```
|
||||||
Some,
|
Some,
|
||||||
|
|
||||||
/// A serialized `()`.
|
/// A serialized `()`.
|
||||||
///
|
///
|
||||||
/// ```edition2018
|
/// ```edition2021
|
||||||
/// # use serde_test::{assert_tokens, Token};
|
/// # use serde_test::{assert_tokens, Token};
|
||||||
/// #
|
/// #
|
||||||
/// assert_tokens(&(), &[Token::Unit]);
|
/// assert_tokens(&(), &[Token::Unit]);
|
||||||
@@ -185,8 +182,8 @@ pub enum Token {
|
|||||||
|
|
||||||
/// A serialized unit struct of the given name.
|
/// A serialized unit struct of the given name.
|
||||||
///
|
///
|
||||||
/// ```edition2018
|
/// ```edition2021
|
||||||
/// # use serde::{Serialize, Deserialize};
|
/// # use serde_derive::{Deserialize, Serialize};
|
||||||
/// # use serde_test::{assert_tokens, Token};
|
/// # use serde_test::{assert_tokens, Token};
|
||||||
/// #
|
/// #
|
||||||
/// # fn main() {
|
/// # fn main() {
|
||||||
@@ -200,8 +197,8 @@ pub enum Token {
|
|||||||
|
|
||||||
/// A unit variant of an enum.
|
/// A unit variant of an enum.
|
||||||
///
|
///
|
||||||
/// ```edition2018
|
/// ```edition2021
|
||||||
/// # use serde::{Serialize, Deserialize};
|
/// # use serde_derive::{Deserialize, Serialize};
|
||||||
/// # use serde_test::{assert_tokens, Token};
|
/// # use serde_test::{assert_tokens, Token};
|
||||||
/// #
|
/// #
|
||||||
/// # fn main() {
|
/// # fn main() {
|
||||||
@@ -211,7 +208,13 @@ pub enum Token {
|
|||||||
/// }
|
/// }
|
||||||
///
|
///
|
||||||
/// let a = E::A;
|
/// let a = E::A;
|
||||||
/// assert_tokens(&a, &[Token::UnitVariant { name: "E", variant: "A" }]);
|
/// assert_tokens(
|
||||||
|
/// &a,
|
||||||
|
/// &[Token::UnitVariant {
|
||||||
|
/// name: "E",
|
||||||
|
/// variant: "A",
|
||||||
|
/// }],
|
||||||
|
/// );
|
||||||
/// # }
|
/// # }
|
||||||
/// ```
|
/// ```
|
||||||
UnitVariant {
|
UnitVariant {
|
||||||
@@ -223,8 +226,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.
|
||||||
///
|
///
|
||||||
/// ```edition2018
|
/// ```edition2021
|
||||||
/// # use serde::{Serialize, Deserialize};
|
/// # use serde_derive::{Deserialize, Serialize};
|
||||||
/// # use serde_test::{assert_tokens, Token};
|
/// # use serde_test::{assert_tokens, Token};
|
||||||
/// #
|
/// #
|
||||||
/// # fn main() {
|
/// # fn main() {
|
||||||
@@ -232,10 +235,10 @@ pub enum Token {
|
|||||||
/// struct N(String);
|
/// struct N(String);
|
||||||
///
|
///
|
||||||
/// let n = N("newtype".to_owned());
|
/// let n = N("newtype".to_owned());
|
||||||
/// assert_tokens(&n, &[
|
/// assert_tokens(
|
||||||
/// Token::NewtypeStruct { name: "N" },
|
/// &n,
|
||||||
/// Token::String("newtype"),
|
/// &[Token::NewtypeStruct { name: "N" }, Token::String("newtype")],
|
||||||
/// ]);
|
/// );
|
||||||
/// # }
|
/// # }
|
||||||
/// ```
|
/// ```
|
||||||
NewtypeStruct { name: &'static str },
|
NewtypeStruct { name: &'static str },
|
||||||
@@ -244,8 +247,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.
|
||||||
///
|
///
|
||||||
/// ```edition2018
|
/// ```edition2021
|
||||||
/// # use serde::{Serialize, Deserialize};
|
/// # use serde_derive::{Deserialize, Serialize};
|
||||||
/// # use serde_test::{assert_tokens, Token};
|
/// # use serde_test::{assert_tokens, Token};
|
||||||
/// #
|
/// #
|
||||||
/// # fn main() {
|
/// # fn main() {
|
||||||
@@ -255,10 +258,16 @@ pub enum Token {
|
|||||||
/// }
|
/// }
|
||||||
///
|
///
|
||||||
/// let b = E::B(0);
|
/// let b = E::B(0);
|
||||||
/// assert_tokens(&b, &[
|
/// assert_tokens(
|
||||||
/// Token::NewtypeVariant { name: "E", variant: "B" },
|
/// &b,
|
||||||
/// Token::U8(0),
|
/// &[
|
||||||
/// ]);
|
/// Token::NewtypeVariant {
|
||||||
|
/// name: "E",
|
||||||
|
/// variant: "B",
|
||||||
|
/// },
|
||||||
|
/// Token::U8(0),
|
||||||
|
/// ],
|
||||||
|
/// );
|
||||||
/// # }
|
/// # }
|
||||||
/// ```
|
/// ```
|
||||||
NewtypeVariant {
|
NewtypeVariant {
|
||||||
@@ -271,17 +280,20 @@ 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`.
|
||||||
///
|
///
|
||||||
/// ```edition2018
|
/// ```edition2021
|
||||||
/// # use serde_test::{assert_tokens, Token};
|
/// # use serde_test::{assert_tokens, Token};
|
||||||
/// #
|
/// #
|
||||||
/// let vec = vec!['a', 'b', 'c'];
|
/// let vec = vec!['a', 'b', 'c'];
|
||||||
/// assert_tokens(&vec, &[
|
/// assert_tokens(
|
||||||
/// Token::Seq { len: Some(3) },
|
/// &vec,
|
||||||
/// Token::Char('a'),
|
/// &[
|
||||||
/// Token::Char('b'),
|
/// Token::Seq { len: Some(3) },
|
||||||
/// Token::Char('c'),
|
/// Token::Char('a'),
|
||||||
/// Token::SeqEnd,
|
/// Token::Char('b'),
|
||||||
/// ]);
|
/// Token::Char('c'),
|
||||||
|
/// Token::SeqEnd,
|
||||||
|
/// ],
|
||||||
|
/// );
|
||||||
/// ```
|
/// ```
|
||||||
Seq { len: Option<usize> },
|
Seq { len: Option<usize> },
|
||||||
|
|
||||||
@@ -292,16 +304,19 @@ 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`.
|
||||||
///
|
///
|
||||||
/// ```edition2018
|
/// ```edition2021
|
||||||
/// # use serde_test::{assert_tokens, Token};
|
/// # use serde_test::{assert_tokens, Token};
|
||||||
/// #
|
/// #
|
||||||
/// let tuple = ('a', 100);
|
/// let tuple = ('a', 100);
|
||||||
/// assert_tokens(&tuple, &[
|
/// assert_tokens(
|
||||||
/// Token::Tuple { len: 2 },
|
/// &tuple,
|
||||||
/// Token::Char('a'),
|
/// &[
|
||||||
/// Token::I32(100),
|
/// Token::Tuple { len: 2 },
|
||||||
/// Token::TupleEnd,
|
/// Token::Char('a'),
|
||||||
/// ]);
|
/// Token::I32(100),
|
||||||
|
/// Token::TupleEnd,
|
||||||
|
/// ],
|
||||||
|
/// );
|
||||||
/// ```
|
/// ```
|
||||||
Tuple { len: usize },
|
Tuple { len: usize },
|
||||||
|
|
||||||
@@ -313,8 +328,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`.
|
||||||
///
|
///
|
||||||
/// ```edition2018
|
/// ```edition2021
|
||||||
/// # use serde::{Serialize, Deserialize};
|
/// # use serde_derive::{Deserialize, Serialize};
|
||||||
/// # use serde_test::{assert_tokens, Token};
|
/// # use serde_test::{assert_tokens, Token};
|
||||||
/// #
|
/// #
|
||||||
/// # fn main() {
|
/// # fn main() {
|
||||||
@@ -322,12 +337,15 @@ pub enum Token {
|
|||||||
/// struct T(u8, u8);
|
/// struct T(u8, u8);
|
||||||
///
|
///
|
||||||
/// let t = T(0, 0);
|
/// let t = T(0, 0);
|
||||||
/// assert_tokens(&t, &[
|
/// assert_tokens(
|
||||||
/// Token::TupleStruct { name: "T", len: 2 },
|
/// &t,
|
||||||
/// Token::U8(0),
|
/// &[
|
||||||
/// Token::U8(0),
|
/// Token::TupleStruct { name: "T", len: 2 },
|
||||||
/// Token::TupleStructEnd,
|
/// Token::U8(0),
|
||||||
/// ]);
|
/// Token::U8(0),
|
||||||
|
/// Token::TupleStructEnd,
|
||||||
|
/// ],
|
||||||
|
/// );
|
||||||
/// # }
|
/// # }
|
||||||
/// ```
|
/// ```
|
||||||
TupleStruct { name: &'static str, len: usize },
|
TupleStruct { name: &'static str, len: usize },
|
||||||
@@ -340,8 +358,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`.
|
||||||
///
|
///
|
||||||
/// ```edition2018
|
/// ```edition2021
|
||||||
/// # use serde::{Serialize, Deserialize};
|
/// # use serde_derive::{Deserialize, Serialize};
|
||||||
/// # use serde_test::{assert_tokens, Token};
|
/// # use serde_test::{assert_tokens, Token};
|
||||||
/// #
|
/// #
|
||||||
/// # fn main() {
|
/// # fn main() {
|
||||||
@@ -351,12 +369,19 @@ pub enum Token {
|
|||||||
/// }
|
/// }
|
||||||
///
|
///
|
||||||
/// let c = E::C(0, 0);
|
/// let c = E::C(0, 0);
|
||||||
/// assert_tokens(&c, &[
|
/// assert_tokens(
|
||||||
/// Token::TupleVariant { name: "E", variant: "C", len: 2 },
|
/// &c,
|
||||||
/// Token::U8(0),
|
/// &[
|
||||||
/// Token::U8(0),
|
/// Token::TupleVariant {
|
||||||
/// Token::TupleVariantEnd,
|
/// name: "E",
|
||||||
/// ]);
|
/// variant: "C",
|
||||||
|
/// len: 2,
|
||||||
|
/// },
|
||||||
|
/// Token::U8(0),
|
||||||
|
/// Token::U8(0),
|
||||||
|
/// Token::TupleVariantEnd,
|
||||||
|
/// ],
|
||||||
|
/// );
|
||||||
/// # }
|
/// # }
|
||||||
/// ```
|
/// ```
|
||||||
TupleVariant {
|
TupleVariant {
|
||||||
@@ -372,7 +397,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`.
|
||||||
///
|
///
|
||||||
/// ```edition2018
|
/// ```edition2021
|
||||||
/// # use serde_test::{assert_tokens, Token};
|
/// # use serde_test::{assert_tokens, Token};
|
||||||
/// #
|
/// #
|
||||||
/// use std::collections::BTreeMap;
|
/// use std::collections::BTreeMap;
|
||||||
@@ -381,14 +406,17 @@ pub enum Token {
|
|||||||
/// map.insert('A', 65);
|
/// map.insert('A', 65);
|
||||||
/// map.insert('Z', 90);
|
/// map.insert('Z', 90);
|
||||||
///
|
///
|
||||||
/// assert_tokens(&map, &[
|
/// assert_tokens(
|
||||||
/// Token::Map { len: Some(2) },
|
/// &map,
|
||||||
/// Token::Char('A'),
|
/// &[
|
||||||
/// Token::I32(65),
|
/// Token::Map { len: Some(2) },
|
||||||
/// Token::Char('Z'),
|
/// Token::Char('A'),
|
||||||
/// Token::I32(90),
|
/// Token::I32(65),
|
||||||
/// Token::MapEnd,
|
/// Token::Char('Z'),
|
||||||
/// ]);
|
/// Token::I32(90),
|
||||||
|
/// Token::MapEnd,
|
||||||
|
/// ],
|
||||||
|
/// );
|
||||||
/// ```
|
/// ```
|
||||||
Map { len: Option<usize> },
|
Map { len: Option<usize> },
|
||||||
|
|
||||||
@@ -399,8 +427,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`.
|
||||||
///
|
///
|
||||||
/// ```edition2018
|
/// ```edition2021
|
||||||
/// # use serde::{Serialize, Deserialize};
|
/// # use serde_derive::{Deserialize, Serialize};
|
||||||
/// # use serde_test::{assert_tokens, Token};
|
/// # use serde_test::{assert_tokens, Token};
|
||||||
/// #
|
/// #
|
||||||
/// # fn main() {
|
/// # fn main() {
|
||||||
@@ -411,14 +439,17 @@ pub enum Token {
|
|||||||
/// }
|
/// }
|
||||||
///
|
///
|
||||||
/// let s = S { a: 0, b: 0 };
|
/// let s = S { a: 0, b: 0 };
|
||||||
/// assert_tokens(&s, &[
|
/// assert_tokens(
|
||||||
/// Token::Struct { name: "S", len: 2 },
|
/// &s,
|
||||||
/// Token::Str("a"),
|
/// &[
|
||||||
/// Token::U8(0),
|
/// Token::Struct { name: "S", len: 2 },
|
||||||
/// Token::Str("b"),
|
/// Token::Str("a"),
|
||||||
/// Token::U8(0),
|
/// Token::U8(0),
|
||||||
/// Token::StructEnd,
|
/// Token::Str("b"),
|
||||||
/// ]);
|
/// Token::U8(0),
|
||||||
|
/// Token::StructEnd,
|
||||||
|
/// ],
|
||||||
|
/// );
|
||||||
/// # }
|
/// # }
|
||||||
/// ```
|
/// ```
|
||||||
Struct { name: &'static str, len: usize },
|
Struct { name: &'static str, len: usize },
|
||||||
@@ -431,8 +462,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`.
|
||||||
///
|
///
|
||||||
/// ```edition2018
|
/// ```edition2021
|
||||||
/// # use serde::{Serialize, Deserialize};
|
/// # use serde_derive::{Deserialize, Serialize};
|
||||||
/// # use serde_test::{assert_tokens, Token};
|
/// # use serde_test::{assert_tokens, Token};
|
||||||
/// #
|
/// #
|
||||||
/// # fn main() {
|
/// # fn main() {
|
||||||
@@ -442,12 +473,19 @@ pub enum Token {
|
|||||||
/// }
|
/// }
|
||||||
///
|
///
|
||||||
/// let d = E::D { d: 0 };
|
/// let d = E::D { d: 0 };
|
||||||
/// assert_tokens(&d, &[
|
/// assert_tokens(
|
||||||
/// Token::StructVariant { name: "E", variant: "D", len: 1 },
|
/// &d,
|
||||||
/// Token::Str("d"),
|
/// &[
|
||||||
/// Token::U8(0),
|
/// Token::StructVariant {
|
||||||
/// Token::StructVariantEnd,
|
/// name: "E",
|
||||||
/// ]);
|
/// variant: "D",
|
||||||
|
/// len: 1,
|
||||||
|
/// },
|
||||||
|
/// Token::Str("d"),
|
||||||
|
/// Token::U8(0),
|
||||||
|
/// Token::StructVariantEnd,
|
||||||
|
/// ],
|
||||||
|
/// );
|
||||||
/// # }
|
/// # }
|
||||||
/// ```
|
/// ```
|
||||||
StructVariant {
|
StructVariant {
|
||||||
@@ -461,8 +499,8 @@ pub enum Token {
|
|||||||
|
|
||||||
/// The header to an enum of the given name.
|
/// The header to an enum of the given name.
|
||||||
///
|
///
|
||||||
/// ```edition2018
|
/// ```edition2021
|
||||||
/// # use serde::{Serialize, Deserialize};
|
/// # use serde_derive::{Deserialize, Serialize};
|
||||||
/// # use serde_test::{assert_tokens, Token};
|
/// # use serde_test::{assert_tokens, Token};
|
||||||
/// #
|
/// #
|
||||||
/// # fn main() {
|
/// # fn main() {
|
||||||
@@ -475,38 +513,42 @@ pub enum Token {
|
|||||||
/// }
|
/// }
|
||||||
///
|
///
|
||||||
/// let a = E::A;
|
/// let a = E::A;
|
||||||
/// assert_tokens(&a, &[
|
/// assert_tokens(
|
||||||
/// Token::Enum { name: "E" },
|
/// &a,
|
||||||
/// Token::Str("A"),
|
/// &[Token::Enum { name: "E" }, Token::Str("A"), Token::Unit],
|
||||||
/// Token::Unit,
|
/// );
|
||||||
/// ]);
|
|
||||||
///
|
///
|
||||||
/// let b = E::B(0);
|
/// let b = E::B(0);
|
||||||
/// assert_tokens(&b, &[
|
/// assert_tokens(
|
||||||
/// Token::Enum { name: "E" },
|
/// &b,
|
||||||
/// Token::Str("B"),
|
/// &[Token::Enum { name: "E" }, Token::Str("B"), Token::U8(0)],
|
||||||
/// Token::U8(0),
|
/// );
|
||||||
/// ]);
|
|
||||||
///
|
///
|
||||||
/// let c = E::C(0, 0);
|
/// let c = E::C(0, 0);
|
||||||
/// assert_tokens(&c, &[
|
/// assert_tokens(
|
||||||
/// Token::Enum { name: "E" },
|
/// &c,
|
||||||
/// Token::Str("C"),
|
/// &[
|
||||||
/// Token::Seq { len: Some(2) },
|
/// Token::Enum { name: "E" },
|
||||||
/// Token::U8(0),
|
/// Token::Str("C"),
|
||||||
/// Token::U8(0),
|
/// Token::Seq { len: Some(2) },
|
||||||
/// Token::SeqEnd,
|
/// Token::U8(0),
|
||||||
/// ]);
|
/// Token::U8(0),
|
||||||
|
/// Token::SeqEnd,
|
||||||
|
/// ],
|
||||||
|
/// );
|
||||||
///
|
///
|
||||||
/// let d = E::D { d: 0 };
|
/// let d = E::D { d: 0 };
|
||||||
/// assert_tokens(&d, &[
|
/// assert_tokens(
|
||||||
/// Token::Enum { name: "E" },
|
/// &d,
|
||||||
/// Token::Str("D"),
|
/// &[
|
||||||
/// Token::Map { len: Some(1) },
|
/// Token::Enum { name: "E" },
|
||||||
/// Token::Str("d"),
|
/// Token::Str("D"),
|
||||||
/// Token::U8(0),
|
/// Token::Map { len: Some(1) },
|
||||||
/// Token::MapEnd,
|
/// Token::Str("d"),
|
||||||
/// ]);
|
/// Token::U8(0),
|
||||||
|
/// Token::MapEnd,
|
||||||
|
/// ],
|
||||||
|
/// );
|
||||||
/// # }
|
/// # }
|
||||||
/// ```
|
/// ```
|
||||||
Enum { name: &'static str },
|
Enum { name: &'static str },
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ unstable = ["serde/unstable"]
|
|||||||
serde = { path = "../serde" }
|
serde = { path = "../serde" }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
automod = "1.0"
|
automod = "1.0.1"
|
||||||
fnv = "1.0"
|
fnv = "1.0"
|
||||||
rustversion = "1.0"
|
rustversion = "1.0"
|
||||||
serde = { path = "../serde", features = ["rc", "derive"] }
|
serde = { path = "../serde", features = ["rc", "derive"] }
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ fn panic(_info: &core::panic::PanicInfo) -> ! {
|
|||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
use serde::{Serialize, Deserialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Serialize, Deserialize)]
|
||||||
struct Unit;
|
struct Unit;
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
clippy::uninlined_format_args,
|
clippy::uninlined_format_args,
|
||||||
)]
|
)]
|
||||||
|
|
||||||
use serde::de::{self, MapAccess, Unexpected, Visitor};
|
use serde::de::{self, IgnoredAny, MapAccess, Unexpected, Visitor};
|
||||||
use serde::{Deserialize, Deserializer, Serialize, Serializer};
|
use serde::{Deserialize, Deserializer, Serialize, Serializer};
|
||||||
|
|
||||||
use std::collections::{BTreeMap, HashMap};
|
use std::collections::{BTreeMap, HashMap};
|
||||||
@@ -2697,6 +2697,31 @@ fn test_flatten_option() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_flatten_ignored_any() {
|
||||||
|
#[derive(Deserialize, PartialEq, Debug)]
|
||||||
|
struct Outer {
|
||||||
|
#[serde(flatten)]
|
||||||
|
inner: IgnoredAny,
|
||||||
|
}
|
||||||
|
|
||||||
|
assert_de_tokens(
|
||||||
|
&Outer { inner: IgnoredAny },
|
||||||
|
&[Token::Map { len: None }, Token::MapEnd],
|
||||||
|
);
|
||||||
|
|
||||||
|
assert_de_tokens(
|
||||||
|
&Outer { inner: IgnoredAny },
|
||||||
|
&[
|
||||||
|
Token::Struct {
|
||||||
|
name: "DoNotMatter",
|
||||||
|
len: 0,
|
||||||
|
},
|
||||||
|
Token::StructEnd,
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_transparent_struct() {
|
fn test_transparent_struct() {
|
||||||
#[derive(Serialize, Deserialize, PartialEq, Debug)]
|
#[derive(Serialize, Deserialize, PartialEq, Debug)]
|
||||||
|
|||||||
@@ -46,6 +46,9 @@ mod macros;
|
|||||||
#[derive(Copy, Clone, PartialEq, Debug, Deserialize)]
|
#[derive(Copy, Clone, PartialEq, Debug, Deserialize)]
|
||||||
struct UnitStruct;
|
struct UnitStruct;
|
||||||
|
|
||||||
|
#[derive(Copy, Clone, PartialEq, Debug, Deserialize)]
|
||||||
|
struct GenericUnitStruct<const N: u8>;
|
||||||
|
|
||||||
#[derive(PartialEq, Debug, Deserialize)]
|
#[derive(PartialEq, Debug, Deserialize)]
|
||||||
struct NewtypeStruct(i32);
|
struct NewtypeStruct(i32);
|
||||||
|
|
||||||
@@ -883,6 +886,17 @@ fn test_unit_struct() {
|
|||||||
test(UnitStruct, &[Token::UnitStruct { name: "UnitStruct" }]);
|
test(UnitStruct, &[Token::UnitStruct { name: "UnitStruct" }]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_generic_unit_struct() {
|
||||||
|
test(GenericUnitStruct::<8>, &[Token::Unit]);
|
||||||
|
test(
|
||||||
|
GenericUnitStruct::<8>,
|
||||||
|
&[Token::UnitStruct {
|
||||||
|
name: "GenericUnitStruct",
|
||||||
|
}],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_newtype_struct() {
|
fn test_newtype_struct() {
|
||||||
test(
|
test(
|
||||||
|
|||||||
@@ -760,6 +760,10 @@ fn test_gen() {
|
|||||||
#[serde(serialize_with = "vec_first_element")]
|
#[serde(serialize_with = "vec_first_element")]
|
||||||
vec: Vec<Self>,
|
vec: Vec<Self>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Deserialize)]
|
||||||
|
#[serde(bound(deserialize = "[&'de str; N]: Copy"))]
|
||||||
|
struct GenericUnitStruct<const N: usize>;
|
||||||
}
|
}
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
|
|||||||
@@ -1267,6 +1267,38 @@ fn test_adjacently_tagged_enum() {
|
|||||||
Token::StructEnd,
|
Token::StructEnd,
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// integer field keys
|
||||||
|
assert_de_tokens(
|
||||||
|
&AdjacentlyTagged::Newtype::<u8>(1),
|
||||||
|
&[
|
||||||
|
Token::Struct {
|
||||||
|
name: "AdjacentlyTagged",
|
||||||
|
len: 2,
|
||||||
|
},
|
||||||
|
Token::U64(1), // content field
|
||||||
|
Token::U8(1),
|
||||||
|
Token::U64(0), // tag field
|
||||||
|
Token::Str("Newtype"),
|
||||||
|
Token::StructEnd,
|
||||||
|
],
|
||||||
|
);
|
||||||
|
|
||||||
|
// byte-array field keys
|
||||||
|
assert_de_tokens(
|
||||||
|
&AdjacentlyTagged::Newtype::<u8>(1),
|
||||||
|
&[
|
||||||
|
Token::Struct {
|
||||||
|
name: "AdjacentlyTagged",
|
||||||
|
len: 2,
|
||||||
|
},
|
||||||
|
Token::Bytes(b"c"),
|
||||||
|
Token::U8(1),
|
||||||
|
Token::Bytes(b"t"),
|
||||||
|
Token::Str("Newtype"),
|
||||||
|
Token::StructEnd,
|
||||||
|
],
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -1330,6 +1362,32 @@ fn test_adjacently_tagged_enum_deny_unknown_fields() {
|
|||||||
],
|
],
|
||||||
r#"invalid value: string "h", expected "t" or "c""#,
|
r#"invalid value: string "h", expected "t" or "c""#,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
assert_de_tokens_error::<AdjacentlyTagged>(
|
||||||
|
&[
|
||||||
|
Token::Struct {
|
||||||
|
name: "AdjacentlyTagged",
|
||||||
|
len: 2,
|
||||||
|
},
|
||||||
|
Token::U64(0), // tag field
|
||||||
|
Token::Str("Unit"),
|
||||||
|
Token::U64(3),
|
||||||
|
],
|
||||||
|
r#"invalid value: integer `3`, expected "t" or "c""#,
|
||||||
|
);
|
||||||
|
|
||||||
|
assert_de_tokens_error::<AdjacentlyTagged>(
|
||||||
|
&[
|
||||||
|
Token::Struct {
|
||||||
|
name: "AdjacentlyTagged",
|
||||||
|
len: 2,
|
||||||
|
},
|
||||||
|
Token::Bytes(b"c"),
|
||||||
|
Token::Unit,
|
||||||
|
Token::Bytes(b"h"),
|
||||||
|
],
|
||||||
|
r#"invalid value: byte array, expected "t" or "c""#,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
use serde::Serialize;
|
||||||
|
|
||||||
|
#[derive(Serialize)]
|
||||||
|
#[serde(bound = ""huh)]
|
||||||
|
pub struct Struct {
|
||||||
|
#[serde(rename = ""what)]
|
||||||
|
pub field: i32,
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
error: unexpected suffix `huh` on string literal
|
||||||
|
--> tests/ui/malformed/str_suffix.rs:4:17
|
||||||
|
|
|
||||||
|
4 | #[serde(bound = ""huh)]
|
||||||
|
| ^^^^^
|
||||||
|
|
||||||
|
error: unexpected suffix `what` on string literal
|
||||||
|
--> tests/ui/malformed/str_suffix.rs:6:22
|
||||||
|
|
|
||||||
|
6 | #[serde(rename = ""what)]
|
||||||
|
| ^^^^^^
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
use serde_derive::{Serialize, Deserialize};
|
use serde_derive::{Deserialize, Serialize};
|
||||||
|
|
||||||
mod remote {
|
mod remote {
|
||||||
pub struct S {
|
pub struct S {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
use serde_derive::{Serialize, Deserialize};
|
use serde_derive::{Deserialize, Serialize};
|
||||||
|
|
||||||
mod remote {
|
mod remote {
|
||||||
pub struct S {
|
pub struct S {
|
||||||
|
|||||||
Reference in New Issue
Block a user