mirror of
https://github.com/pezkuwichain/serde.git
synced 2026-06-22 20:41:07 +00:00
Compare commits
12 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 60cbbacdb3 | |||
| befc7edc17 | |||
| 3897ccb3f9 | |||
| 11c5fd78ad | |||
| cbfdba3826 | |||
| 5985b7edaf | |||
| d28a0e66c8 | |||
| 0ca4db1616 | |||
| 72b3438dfc | |||
| c7051ac748 | |||
| a065db9838 | |||
| 3ca0597a7e |
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "serde"
|
name = "serde"
|
||||||
version = "1.0.71" # remember to update html_root_url
|
version = "1.0.72" # remember to update html_root_url
|
||||||
authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>", "David Tolnay <dtolnay@gmail.com>"]
|
authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>", "David Tolnay <dtolnay@gmail.com>"]
|
||||||
license = "MIT/Apache-2.0"
|
license = "MIT/Apache-2.0"
|
||||||
description = "A generic serialization/deserialization framework"
|
description = "A generic serialization/deserialization framework"
|
||||||
|
|||||||
@@ -20,7 +20,9 @@ use de::{Deserialize, Deserializer, Error, MapAccess, SeqAccess, Visitor};
|
|||||||
/// use std::fmt;
|
/// use std::fmt;
|
||||||
/// use std::marker::PhantomData;
|
/// use std::marker::PhantomData;
|
||||||
///
|
///
|
||||||
/// use serde::de::{self, Deserialize, DeserializeSeed, Deserializer, Visitor, SeqAccess, IgnoredAny};
|
/// use serde::de::{
|
||||||
|
/// self, Deserialize, DeserializeSeed, Deserializer, IgnoredAny, SeqAccess, Visitor,
|
||||||
|
/// };
|
||||||
///
|
///
|
||||||
/// /// 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`.
|
||||||
@@ -51,7 +53,11 @@ use de::{Deserialize, Deserializer, Error, MapAccess, SeqAccess, Visitor};
|
|||||||
/// type Value = T;
|
/// type Value = T;
|
||||||
///
|
///
|
||||||
/// fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
/// fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||||
/// write!(formatter, "a sequence in which we care about element {}", self.n)
|
/// write!(
|
||||||
|
/// formatter,
|
||||||
|
/// "a sequence in which we care about element {}",
|
||||||
|
/// self.n
|
||||||
|
/// )
|
||||||
/// }
|
/// }
|
||||||
///
|
///
|
||||||
/// fn visit_seq<A>(self, mut seq: A) -> Result<Self::Value, A::Error>
|
/// fn visit_seq<A>(self, mut seq: A) -> Result<Self::Value, A::Error>
|
||||||
|
|||||||
+25
-35
@@ -1602,13 +1602,11 @@ forwarded_impl!((T), Box<[T]>, Vec::into_boxed_slice);
|
|||||||
#[cfg(any(feature = "std", feature = "alloc"))]
|
#[cfg(any(feature = "std", feature = "alloc"))]
|
||||||
forwarded_impl!((), Box<str>, String::into_boxed_str);
|
forwarded_impl!((), Box<str>, String::into_boxed_str);
|
||||||
|
|
||||||
#[cfg(
|
#[cfg(all(
|
||||||
all(
|
not(de_rc_dst),
|
||||||
not(de_rc_dst),
|
feature = "rc",
|
||||||
feature = "rc",
|
any(feature = "std", feature = "alloc")
|
||||||
any(feature = "std", feature = "alloc")
|
))]
|
||||||
)
|
|
||||||
)]
|
|
||||||
forwarded_impl! {
|
forwarded_impl! {
|
||||||
/// This impl requires the [`"rc"`] Cargo feature of Serde.
|
/// This impl requires the [`"rc"`] Cargo feature of Serde.
|
||||||
///
|
///
|
||||||
@@ -1620,13 +1618,11 @@ forwarded_impl! {
|
|||||||
(T), Arc<T>, Arc::new
|
(T), Arc<T>, Arc::new
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(
|
#[cfg(all(
|
||||||
all(
|
not(de_rc_dst),
|
||||||
not(de_rc_dst),
|
feature = "rc",
|
||||||
feature = "rc",
|
any(feature = "std", feature = "alloc")
|
||||||
any(feature = "std", feature = "alloc")
|
))]
|
||||||
)
|
|
||||||
)]
|
|
||||||
forwarded_impl! {
|
forwarded_impl! {
|
||||||
/// This impl requires the [`"rc"`] Cargo feature of Serde.
|
/// This impl requires the [`"rc"`] Cargo feature of Serde.
|
||||||
///
|
///
|
||||||
@@ -1693,13 +1689,11 @@ where
|
|||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#[cfg(
|
#[cfg(all(
|
||||||
all(
|
de_rc_dst,
|
||||||
de_rc_dst,
|
feature = "rc",
|
||||||
feature = "rc",
|
any(feature = "std", feature = "alloc")
|
||||||
any(feature = "std", feature = "alloc")
|
))]
|
||||||
)
|
|
||||||
)]
|
|
||||||
macro_rules! box_forwarded_impl {
|
macro_rules! box_forwarded_impl {
|
||||||
(
|
(
|
||||||
$(#[doc = $doc:tt])*
|
$(#[doc = $doc:tt])*
|
||||||
@@ -1720,13 +1714,11 @@ macro_rules! box_forwarded_impl {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(
|
#[cfg(all(
|
||||||
all(
|
de_rc_dst,
|
||||||
de_rc_dst,
|
feature = "rc",
|
||||||
feature = "rc",
|
any(feature = "std", feature = "alloc")
|
||||||
any(feature = "std", feature = "alloc")
|
))]
|
||||||
)
|
|
||||||
)]
|
|
||||||
box_forwarded_impl! {
|
box_forwarded_impl! {
|
||||||
/// This impl requires the [`"rc"`] Cargo feature of Serde.
|
/// This impl requires the [`"rc"`] Cargo feature of Serde.
|
||||||
///
|
///
|
||||||
@@ -1738,13 +1730,11 @@ box_forwarded_impl! {
|
|||||||
Rc
|
Rc
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(
|
#[cfg(all(
|
||||||
all(
|
de_rc_dst,
|
||||||
de_rc_dst,
|
feature = "rc",
|
||||||
feature = "rc",
|
any(feature = "std", feature = "alloc")
|
||||||
any(feature = "std", feature = "alloc")
|
))]
|
||||||
)
|
|
||||||
)]
|
|
||||||
box_forwarded_impl! {
|
box_forwarded_impl! {
|
||||||
/// This impl requires the [`"rc"`] Cargo feature of Serde.
|
/// This impl requires the [`"rc"`] Cargo feature of Serde.
|
||||||
///
|
///
|
||||||
|
|||||||
+29
-27
@@ -24,8 +24,7 @@
|
|||||||
//!
|
//!
|
||||||
//! Additionally, Serde provides a procedural macro called [`serde_derive`] to
|
//! Additionally, Serde provides a procedural macro called [`serde_derive`] to
|
||||||
//! automatically generate [`Deserialize`] implementations for structs and enums
|
//! automatically generate [`Deserialize`] implementations for structs and enums
|
||||||
//! in your program. See the [codegen section of the manual] for how to use
|
//! in your program. See the [derive section of the manual] for how to use this.
|
||||||
//! this.
|
|
||||||
//!
|
//!
|
||||||
//! In rare cases it may be necessary to implement [`Deserialize`] manually for
|
//! In rare cases it may be necessary to implement [`Deserialize`] manually for
|
||||||
//! some type in your program. See the [Implementing `Deserialize`] section of
|
//! some type in your program. See the [Implementing `Deserialize`] section of
|
||||||
@@ -117,7 +116,7 @@
|
|||||||
//! [`serde_derive`]: https://crates.io/crates/serde_derive
|
//! [`serde_derive`]: https://crates.io/crates/serde_derive
|
||||||
//! [`serde_json`]: https://github.com/serde-rs/json
|
//! [`serde_json`]: https://github.com/serde-rs/json
|
||||||
//! [`serde_yaml`]: https://github.com/dtolnay/serde-yaml
|
//! [`serde_yaml`]: https://github.com/dtolnay/serde-yaml
|
||||||
//! [codegen section of the manual]: https://serde.rs/codegen.html
|
//! [derive section of the manual]: https://serde.rs/derive.html
|
||||||
//! [data formats]: https://serde.rs/#data-formats
|
//! [data formats]: https://serde.rs/#data-formats
|
||||||
|
|
||||||
use lib::*;
|
use lib::*;
|
||||||
@@ -498,7 +497,7 @@ impl<'a> Display for Expected + 'a {
|
|||||||
///
|
///
|
||||||
/// Additionally, Serde provides a procedural macro called `serde_derive` to
|
/// Additionally, Serde provides a procedural macro called `serde_derive` to
|
||||||
/// automatically generate `Deserialize` implementations for structs and enums
|
/// automatically generate `Deserialize` implementations for structs and enums
|
||||||
/// in your program. See the [codegen section of the manual][codegen] for how to
|
/// in your program. See the [derive section of the manual][derive] for how to
|
||||||
/// use this.
|
/// use this.
|
||||||
///
|
///
|
||||||
/// In rare cases it may be necessary to implement `Deserialize` manually for
|
/// In rare cases it may be necessary to implement `Deserialize` manually for
|
||||||
@@ -511,7 +510,7 @@ impl<'a> Display for Expected + 'a {
|
|||||||
/// provides an implementation of `Deserialize` for it.
|
/// provides an implementation of `Deserialize` for it.
|
||||||
///
|
///
|
||||||
/// [de]: https://docs.serde.rs/serde/de/index.html
|
/// [de]: https://docs.serde.rs/serde/de/index.html
|
||||||
/// [codegen]: https://serde.rs/codegen.html
|
/// [derive]: https://serde.rs/derive.html
|
||||||
/// [impl-deserialize]: https://serde.rs/impl-deserialize.html
|
/// [impl-deserialize]: https://serde.rs/impl-deserialize.html
|
||||||
///
|
///
|
||||||
/// # Lifetime
|
/// # Lifetime
|
||||||
@@ -660,7 +659,7 @@ impl<T> DeserializeOwned for T where T: for<'de> Deserialize<'de> {}
|
|||||||
/// use std::fmt;
|
/// use std::fmt;
|
||||||
/// use std::marker::PhantomData;
|
/// use std::marker::PhantomData;
|
||||||
///
|
///
|
||||||
/// use serde::de::{Deserialize, DeserializeSeed, Deserializer, Visitor, SeqAccess};
|
/// 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
|
||||||
@@ -807,16 +806,16 @@ where
|
|||||||
/// - When serializing, all strings are handled equally. When deserializing,
|
/// - When serializing, all strings are handled equally. When deserializing,
|
||||||
/// there are three flavors of strings: transient, owned, and borrowed.
|
/// there are three flavors of strings: transient, owned, and borrowed.
|
||||||
/// - **byte array** - \[u8\]
|
/// - **byte array** - \[u8\]
|
||||||
/// - Similar to strings, during deserialization byte arrays can be transient,
|
/// - Similar to strings, during deserialization byte arrays can be
|
||||||
/// owned, or borrowed.
|
/// transient, owned, or borrowed.
|
||||||
/// - **option**
|
/// - **option**
|
||||||
/// - Either none or some value.
|
/// - Either none or some value.
|
||||||
/// - **unit**
|
/// - **unit**
|
||||||
/// - The type of `()` in Rust. It represents an anonymous value containing no
|
/// - The type of `()` in Rust. It represents an anonymous value containing
|
||||||
/// data.
|
/// no data.
|
||||||
/// - **unit_struct**
|
/// - **unit_struct**
|
||||||
/// - For example `struct Unit` or `PhantomData<T>`. It represents a named value
|
/// - For example `struct Unit` or `PhantomData<T>`. It represents a named
|
||||||
/// containing no data.
|
/// value containing no data.
|
||||||
/// - **unit_variant**
|
/// - **unit_variant**
|
||||||
/// - For example the `E::A` and `E::B` in `enum E { A, B }`.
|
/// - For example the `E::A` and `E::B` in `enum E { A, B }`.
|
||||||
/// - **newtype_struct**
|
/// - **newtype_struct**
|
||||||
@@ -824,14 +823,15 @@ where
|
|||||||
/// - **newtype_variant**
|
/// - **newtype_variant**
|
||||||
/// - For example the `E::N` in `enum E { N(u8) }`.
|
/// - For example the `E::N` in `enum E { N(u8) }`.
|
||||||
/// - **seq**
|
/// - **seq**
|
||||||
/// - A variably sized heterogeneous sequence of values, for example `Vec<T>` or
|
/// - A variably sized heterogeneous sequence of values, for example `Vec<T>`
|
||||||
/// `HashSet<T>`. When serializing, the length may or may not be known before
|
/// or `HashSet<T>`. When serializing, the length may or may not be known
|
||||||
/// iterating through all the data. When deserializing, the length is determined
|
/// before iterating through all the data. When deserializing, the length
|
||||||
/// by looking at the serialized data.
|
/// is determined by looking at the serialized data.
|
||||||
/// - **tuple**
|
/// - **tuple**
|
||||||
/// - A statically sized heterogeneous sequence of values for which the length
|
/// - A statically sized heterogeneous sequence of values for which the
|
||||||
/// will be known at deserialization time without looking at the serialized
|
/// length will be known at deserialization time without looking at the
|
||||||
/// data, for example `(u8,)` or `(String, u64, Vec<T>)` or `[u64; 10]`.
|
/// serialized data, for example `(u8,)` or `(String, u64, Vec<T>)` or
|
||||||
|
/// `[u64; 10]`.
|
||||||
/// - **tuple_struct**
|
/// - **tuple_struct**
|
||||||
/// - A named tuple, for example `struct Rgb(u8, u8, u8)`.
|
/// - A named tuple, for example `struct Rgb(u8, u8, u8)`.
|
||||||
/// - **tuple_variant**
|
/// - **tuple_variant**
|
||||||
@@ -839,9 +839,9 @@ where
|
|||||||
/// - **map**
|
/// - **map**
|
||||||
/// - A heterogeneous key-value pairing, for example `BTreeMap<K, V>`.
|
/// - A heterogeneous key-value pairing, for example `BTreeMap<K, V>`.
|
||||||
/// - **struct**
|
/// - **struct**
|
||||||
/// - A heterogeneous key-value pairing in which the keys are strings and will be
|
/// - A heterogeneous key-value pairing in which the keys are strings and
|
||||||
/// known at deserialization time without looking at the serialized data, for
|
/// will be known at deserialization time without looking at the serialized
|
||||||
/// example `struct S { r: u8, g: u8, b: u8 }`.
|
/// data, for example `struct S { r: u8, g: u8, b: u8 }`.
|
||||||
/// - **struct_variant**
|
/// - **struct_variant**
|
||||||
/// - For example the `E::S` in `enum E { S { r: u8, g: u8, b: u8 } }`.
|
/// - For example the `E::S` in `enum E { S { r: u8, g: u8, b: u8 } }`.
|
||||||
///
|
///
|
||||||
@@ -856,7 +856,8 @@ where
|
|||||||
/// type it sees in the input. JSON uses this approach when deserializing
|
/// type it sees in the input. JSON uses this approach when deserializing
|
||||||
/// `serde_json::Value` which is an enum that can represent any JSON
|
/// `serde_json::Value` which is an enum that can represent any JSON
|
||||||
/// document. Without knowing what is in a JSON document, we can deserialize
|
/// document. Without knowing what is in a JSON document, we can deserialize
|
||||||
/// it to `serde_json::Value` by going through `Deserializer::deserialize_any`.
|
/// it to `serde_json::Value` by going through
|
||||||
|
/// `Deserializer::deserialize_any`.
|
||||||
///
|
///
|
||||||
/// 2. The various `deserialize_*` methods. Non-self-describing formats like
|
/// 2. The various `deserialize_*` methods. Non-self-describing formats like
|
||||||
/// Bincode need to be told what is in the input in order to deserialize it.
|
/// Bincode need to be told what is in the input in order to deserialize it.
|
||||||
@@ -866,10 +867,11 @@ where
|
|||||||
/// `Deserializer::deserialize_any`.
|
/// `Deserializer::deserialize_any`.
|
||||||
///
|
///
|
||||||
/// When implementing `Deserialize`, you should avoid relying on
|
/// When implementing `Deserialize`, you should avoid relying on
|
||||||
/// `Deserializer::deserialize_any` unless you need to be told by the Deserializer
|
/// `Deserializer::deserialize_any` unless you need to be told by the
|
||||||
/// what type is in the input. Know that relying on `Deserializer::deserialize_any`
|
/// Deserializer what type is in the input. Know that relying on
|
||||||
/// means your data type will be able to deserialize from self-describing
|
/// `Deserializer::deserialize_any` means your data type will be able to
|
||||||
/// formats only, ruling out Bincode and many others.
|
/// deserialize from self-describing formats only, ruling out Bincode and many
|
||||||
|
/// others.
|
||||||
///
|
///
|
||||||
/// [Serde data model]: https://serde.rs/data-model.html
|
/// [Serde data model]: https://serde.rs/data-model.html
|
||||||
///
|
///
|
||||||
|
|||||||
+2
-2
@@ -82,7 +82,7 @@
|
|||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
// Serde types in rustdoc of other crates get linked to here.
|
// Serde types in rustdoc of other crates get linked to here.
|
||||||
#![doc(html_root_url = "https://docs.rs/serde/1.0.71")]
|
#![doc(html_root_url = "https://docs.rs/serde/1.0.72")]
|
||||||
// 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
|
||||||
@@ -196,7 +196,7 @@ mod lib {
|
|||||||
pub use std::rc::{Rc, Weak as RcWeak};
|
pub use std::rc::{Rc, Weak as RcWeak};
|
||||||
|
|
||||||
#[cfg(all(feature = "rc", feature = "alloc", not(feature = "std")))]
|
#[cfg(all(feature = "rc", feature = "alloc", not(feature = "std")))]
|
||||||
pub use alloc::arc::{Arc, Weak as ArcWeak};
|
pub use alloc::sync::{Arc, Weak as ArcWeak};
|
||||||
#[cfg(all(feature = "rc", feature = "std"))]
|
#[cfg(all(feature = "rc", feature = "std"))]
|
||||||
pub use std::sync::{Arc, Weak as ArcWeak};
|
pub use std::sync::{Arc, Weak as ArcWeak};
|
||||||
|
|
||||||
|
|||||||
@@ -832,8 +832,8 @@ mod content {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'de, T> TaggedContentVisitor<'de, T> {
|
impl<'de, T> TaggedContentVisitor<'de, T> {
|
||||||
/// Visitor for the content of an internally tagged enum with the given tag
|
/// Visitor for the content of an internally tagged enum with the given
|
||||||
/// name.
|
/// tag name.
|
||||||
pub fn new(name: &'static str) -> Self {
|
pub fn new(name: &'static str) -> Self {
|
||||||
TaggedContentVisitor {
|
TaggedContentVisitor {
|
||||||
tag_name: name,
|
tag_name: name,
|
||||||
@@ -1075,8 +1075,8 @@ mod content {
|
|||||||
Ok(value)
|
Ok(value)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Used when deserializing an internally tagged enum because the content will
|
/// Used when deserializing an internally tagged enum because the content
|
||||||
/// be used exactly once.
|
/// will be used exactly once.
|
||||||
impl<'de, E> Deserializer<'de> for ContentDeserializer<'de, E>
|
impl<'de, E> Deserializer<'de> for ContentDeserializer<'de, E>
|
||||||
where
|
where
|
||||||
E: de::Error,
|
E: de::Error,
|
||||||
@@ -1790,8 +1790,8 @@ mod content {
|
|||||||
Ok(value)
|
Ok(value)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Used when deserializing an untagged enum because the content may need to be
|
/// Used when deserializing an untagged enum because the content may need
|
||||||
/// used more than once.
|
/// to be used more than once.
|
||||||
impl<'de, 'a, E> Deserializer<'de> for ContentRefDeserializer<'a, 'de, E>
|
impl<'de, 'a, E> Deserializer<'de> for ContentRefDeserializer<'a, 'de, E>
|
||||||
where
|
where
|
||||||
E: de::Error,
|
E: de::Error,
|
||||||
|
|||||||
+44
-36
@@ -24,8 +24,7 @@
|
|||||||
//!
|
//!
|
||||||
//! Additionally, Serde provides a procedural macro called [`serde_derive`] to
|
//! Additionally, Serde provides a procedural macro called [`serde_derive`] to
|
||||||
//! automatically generate [`Serialize`] implementations for structs and enums
|
//! automatically generate [`Serialize`] implementations for structs and enums
|
||||||
//! in your program. See the [codegen section of the manual] for how to use
|
//! in your program. See the [derive section of the manual] for how to use this.
|
||||||
//! this.
|
|
||||||
//!
|
//!
|
||||||
//! In rare cases it may be necessary to implement [`Serialize`] manually for
|
//! In rare cases it may be necessary to implement [`Serialize`] manually for
|
||||||
//! some type in your program. See the [Implementing `Serialize`] section of the
|
//! some type in your program. See the [Implementing `Serialize`] section of the
|
||||||
@@ -112,7 +111,7 @@
|
|||||||
//! [`serde_derive`]: https://crates.io/crates/serde_derive
|
//! [`serde_derive`]: https://crates.io/crates/serde_derive
|
||||||
//! [`serde_json`]: https://github.com/serde-rs/json
|
//! [`serde_json`]: https://github.com/serde-rs/json
|
||||||
//! [`serde_yaml`]: https://github.com/dtolnay/serde-yaml
|
//! [`serde_yaml`]: https://github.com/dtolnay/serde-yaml
|
||||||
//! [codegen section of the manual]: https://serde.rs/codegen.html
|
//! [derive section of the manual]: https://serde.rs/derive.html
|
||||||
//! [data formats]: https://serde.rs/#data-formats
|
//! [data formats]: https://serde.rs/#data-formats
|
||||||
|
|
||||||
use lib::*;
|
use lib::*;
|
||||||
@@ -196,7 +195,7 @@ declare_error_trait!(Error: Sized + Debug + Display);
|
|||||||
///
|
///
|
||||||
/// Additionally, Serde provides a procedural macro called [`serde_derive`] to
|
/// Additionally, Serde provides a procedural macro called [`serde_derive`] to
|
||||||
/// automatically generate `Serialize` implementations for structs and enums in
|
/// automatically generate `Serialize` implementations for structs and enums in
|
||||||
/// your program. See the [codegen section of the manual] for how to use this.
|
/// your program. See the [derive section of the manual] for how to use this.
|
||||||
///
|
///
|
||||||
/// In rare cases it may be necessary to implement `Serialize` manually for some
|
/// In rare cases it may be necessary to implement `Serialize` manually for some
|
||||||
/// type in your program. See the [Implementing `Serialize`] section of the
|
/// type in your program. See the [Implementing `Serialize`] section of the
|
||||||
@@ -211,7 +210,7 @@ declare_error_trait!(Error: Sized + Debug + Display);
|
|||||||
/// [`LinkedHashMap<K, V>`]: https://docs.rs/linked-hash-map/*/linked_hash_map/struct.LinkedHashMap.html
|
/// [`LinkedHashMap<K, V>`]: https://docs.rs/linked-hash-map/*/linked_hash_map/struct.LinkedHashMap.html
|
||||||
/// [`linked-hash-map`]: https://crates.io/crates/linked-hash-map
|
/// [`linked-hash-map`]: https://crates.io/crates/linked-hash-map
|
||||||
/// [`serde_derive`]: https://crates.io/crates/serde_derive
|
/// [`serde_derive`]: https://crates.io/crates/serde_derive
|
||||||
/// [codegen section of the manual]: https://serde.rs/codegen.html
|
/// [derive section of the manual]: https://serde.rs/derive.html
|
||||||
/// [ser]: https://docs.serde.rs/serde/ser/index.html
|
/// [ser]: https://docs.serde.rs/serde/ser/index.html
|
||||||
pub trait Serialize {
|
pub trait Serialize {
|
||||||
/// Serialize this value into the given Serde serializer.
|
/// Serialize this value into the given Serde serializer.
|
||||||
@@ -220,7 +219,7 @@ pub trait Serialize {
|
|||||||
/// information about how to implement this method.
|
/// information about how to implement this method.
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// use serde::ser::{Serialize, Serializer, SerializeStruct};
|
/// use serde::ser::{Serialize, SerializeStruct, Serializer};
|
||||||
///
|
///
|
||||||
/// struct Person {
|
/// struct Person {
|
||||||
/// name: String,
|
/// name: String,
|
||||||
@@ -274,16 +273,16 @@ pub trait Serialize {
|
|||||||
/// - When serializing, all strings are handled equally. When deserializing,
|
/// - When serializing, all strings are handled equally. When deserializing,
|
||||||
/// there are three flavors of strings: transient, owned, and borrowed.
|
/// there are three flavors of strings: transient, owned, and borrowed.
|
||||||
/// - **byte array** - \[u8\]
|
/// - **byte array** - \[u8\]
|
||||||
/// - Similar to strings, during deserialization byte arrays can be transient,
|
/// - Similar to strings, during deserialization byte arrays can be
|
||||||
/// owned, or borrowed.
|
/// transient, owned, or borrowed.
|
||||||
/// - **option**
|
/// - **option**
|
||||||
/// - Either none or some value.
|
/// - Either none or some value.
|
||||||
/// - **unit**
|
/// - **unit**
|
||||||
/// - The type of `()` in Rust. It represents an anonymous value containing no
|
/// - The type of `()` in Rust. It represents an anonymous value containing
|
||||||
/// data.
|
/// no data.
|
||||||
/// - **unit_struct**
|
/// - **unit_struct**
|
||||||
/// - For example `struct Unit` or `PhantomData<T>`. It represents a named value
|
/// - For example `struct Unit` or `PhantomData<T>`. It represents a named
|
||||||
/// containing no data.
|
/// value containing no data.
|
||||||
/// - **unit_variant**
|
/// - **unit_variant**
|
||||||
/// - For example the `E::A` and `E::B` in `enum E { A, B }`.
|
/// - For example the `E::A` and `E::B` in `enum E { A, B }`.
|
||||||
/// - **newtype_struct**
|
/// - **newtype_struct**
|
||||||
@@ -291,14 +290,15 @@ pub trait Serialize {
|
|||||||
/// - **newtype_variant**
|
/// - **newtype_variant**
|
||||||
/// - For example the `E::N` in `enum E { N(u8) }`.
|
/// - For example the `E::N` in `enum E { N(u8) }`.
|
||||||
/// - **seq**
|
/// - **seq**
|
||||||
/// - A variably sized heterogeneous sequence of values, for example `Vec<T>` or
|
/// - A variably sized heterogeneous sequence of values, for example
|
||||||
/// `HashSet<T>`. When serializing, the length may or may not be known before
|
/// `Vec<T>` or `HashSet<T>`. When serializing, the length may or may not
|
||||||
/// iterating through all the data. When deserializing, the length is determined
|
/// be known before iterating through all the data. When deserializing,
|
||||||
/// by looking at the serialized data.
|
/// the length is determined by looking at the serialized data.
|
||||||
/// - **tuple**
|
/// - **tuple**
|
||||||
/// - A statically sized heterogeneous sequence of values for which the length
|
/// - A statically sized heterogeneous sequence of values for which the
|
||||||
/// will be known at deserialization time without looking at the serialized
|
/// length will be known at deserialization time without looking at the
|
||||||
/// data, for example `(u8,)` or `(String, u64, Vec<T>)` or `[u64; 10]`.
|
/// serialized data, for example `(u8,)` or `(String, u64, Vec<T>)` or
|
||||||
|
/// `[u64; 10]`.
|
||||||
/// - **tuple_struct**
|
/// - **tuple_struct**
|
||||||
/// - A named tuple, for example `struct Rgb(u8, u8, u8)`.
|
/// - A named tuple, for example `struct Rgb(u8, u8, u8)`.
|
||||||
/// - **tuple_variant**
|
/// - **tuple_variant**
|
||||||
@@ -306,9 +306,9 @@ pub trait Serialize {
|
|||||||
/// - **map**
|
/// - **map**
|
||||||
/// - A heterogeneous key-value pairing, for example `BTreeMap<K, V>`.
|
/// - A heterogeneous key-value pairing, for example `BTreeMap<K, V>`.
|
||||||
/// - **struct**
|
/// - **struct**
|
||||||
/// - A heterogeneous key-value pairing in which the keys are strings and will be
|
/// - A heterogeneous key-value pairing in which the keys are strings and
|
||||||
/// known at deserialization time without looking at the serialized data, for
|
/// will be known at deserialization time without looking at the
|
||||||
/// example `struct S { r: u8, g: u8, b: u8 }`.
|
/// serialized data, for example `struct S { r: u8, g: u8, b: u8 }`.
|
||||||
/// - **struct_variant**
|
/// - **struct_variant**
|
||||||
/// - For example the `E::S` in `enum E { S { r: u8, g: u8, b: u8 } }`.
|
/// - For example the `E::S` in `enum E { S { r: u8, g: u8, b: u8 } }`.
|
||||||
///
|
///
|
||||||
@@ -1111,7 +1111,7 @@ pub trait Serializer: Sized {
|
|||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// use serde::ser::{Serialize, Serializer, SerializeTuple};
|
/// use serde::ser::{Serialize, SerializeTuple, Serializer};
|
||||||
///
|
///
|
||||||
/// const VRAM_SIZE: usize = 386;
|
/// const VRAM_SIZE: usize = 386;
|
||||||
/// struct Vram([u16; VRAM_SIZE]);
|
/// struct Vram([u16; VRAM_SIZE]);
|
||||||
@@ -1139,7 +1139,7 @@ pub trait Serializer: Sized {
|
|||||||
/// of data fields that will be serialized.
|
/// of data fields that will be serialized.
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// use serde::ser::{Serialize, Serializer, SerializeTupleStruct};
|
/// use serde::ser::{Serialize, SerializeTupleStruct, Serializer};
|
||||||
///
|
///
|
||||||
/// struct Rgb(u8, u8, u8);
|
/// struct Rgb(u8, u8, u8);
|
||||||
///
|
///
|
||||||
@@ -1171,7 +1171,7 @@ pub trait Serializer: Sized {
|
|||||||
/// and the `len` is the number of data fields that will be serialized.
|
/// and the `len` is the number of data fields that will be serialized.
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// use serde::ser::{Serialize, Serializer, SerializeTupleVariant};
|
/// use serde::ser::{Serialize, SerializeTupleVariant, Serializer};
|
||||||
///
|
///
|
||||||
/// enum E {
|
/// enum E {
|
||||||
/// T(u8, u8),
|
/// T(u8, u8),
|
||||||
@@ -1265,7 +1265,7 @@ pub trait Serializer: Sized {
|
|||||||
/// data fields that will be serialized.
|
/// data fields that will be serialized.
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// use serde::ser::{Serialize, Serializer, SerializeStruct};
|
/// use serde::ser::{Serialize, SerializeStruct, Serializer};
|
||||||
///
|
///
|
||||||
/// struct Rgb {
|
/// struct Rgb {
|
||||||
/// r: u8,
|
/// r: u8,
|
||||||
@@ -1301,10 +1301,10 @@ pub trait Serializer: Sized {
|
|||||||
/// and the `len` is the number of data fields that will be serialized.
|
/// and the `len` is the number of data fields that will be serialized.
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// use serde::ser::{Serialize, Serializer, SerializeStructVariant};
|
/// use serde::ser::{Serialize, SerializeStructVariant, Serializer};
|
||||||
///
|
///
|
||||||
/// enum E {
|
/// enum E {
|
||||||
/// S { r: u8, g: u8, b: u8 }
|
/// S { r: u8, g: u8, b: u8 },
|
||||||
/// }
|
/// }
|
||||||
///
|
///
|
||||||
/// impl Serialize for E {
|
/// impl Serialize for E {
|
||||||
@@ -1313,7 +1313,11 @@ pub trait Serializer: Sized {
|
|||||||
/// S: Serializer,
|
/// S: Serializer,
|
||||||
/// {
|
/// {
|
||||||
/// match *self {
|
/// match *self {
|
||||||
/// E::S { ref r, ref g, ref b } => {
|
/// E::S {
|
||||||
|
/// ref r,
|
||||||
|
/// ref g,
|
||||||
|
/// ref b,
|
||||||
|
/// } => {
|
||||||
/// let mut sv = serializer.serialize_struct_variant("E", 0, "S", 3)?;
|
/// let mut sv = serializer.serialize_struct_variant("E", 0, "S", 3)?;
|
||||||
/// sv.serialize_field("r", r)?;
|
/// sv.serialize_field("r", r)?;
|
||||||
/// sv.serialize_field("g", g)?;
|
/// sv.serialize_field("g", g)?;
|
||||||
@@ -1376,8 +1380,8 @@ pub trait Serializer: Sized {
|
|||||||
/// method.
|
/// method.
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// use std::collections::BTreeSet;
|
|
||||||
/// use serde::{Serialize, Serializer};
|
/// use serde::{Serialize, Serializer};
|
||||||
|
/// use std::collections::BTreeSet;
|
||||||
///
|
///
|
||||||
/// struct MapToUnit {
|
/// struct MapToUnit {
|
||||||
/// keys: BTreeSet<i32>,
|
/// keys: BTreeSet<i32>,
|
||||||
@@ -1705,7 +1709,7 @@ pub trait SerializeTuple {
|
|||||||
/// # Example use
|
/// # Example use
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// use serde::ser::{Serialize, Serializer, SerializeTupleStruct};
|
/// use serde::ser::{Serialize, SerializeTupleStruct, Serializer};
|
||||||
///
|
///
|
||||||
/// struct Rgb(u8, u8, u8);
|
/// struct Rgb(u8, u8, u8);
|
||||||
///
|
///
|
||||||
@@ -1750,7 +1754,7 @@ pub trait SerializeTupleStruct {
|
|||||||
/// # Example use
|
/// # Example use
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// use serde::ser::{Serialize, Serializer, SerializeTupleVariant};
|
/// use serde::ser::{Serialize, SerializeTupleVariant, Serializer};
|
||||||
///
|
///
|
||||||
/// enum E {
|
/// enum E {
|
||||||
/// T(u8, u8),
|
/// T(u8, u8),
|
||||||
@@ -1919,7 +1923,7 @@ pub trait SerializeMap {
|
|||||||
/// # Example use
|
/// # Example use
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// use serde::ser::{Serialize, Serializer, SerializeStruct};
|
/// use serde::ser::{Serialize, SerializeStruct, Serializer};
|
||||||
///
|
///
|
||||||
/// struct Rgb {
|
/// struct Rgb {
|
||||||
/// r: u8,
|
/// r: u8,
|
||||||
@@ -1979,10 +1983,10 @@ pub trait SerializeStruct {
|
|||||||
/// # Example use
|
/// # Example use
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// use serde::ser::{Serialize, Serializer, SerializeStructVariant};
|
/// use serde::ser::{Serialize, SerializeStructVariant, Serializer};
|
||||||
///
|
///
|
||||||
/// enum E {
|
/// enum E {
|
||||||
/// S { r: u8, g: u8, b: u8 }
|
/// S { r: u8, g: u8, b: u8 },
|
||||||
/// }
|
/// }
|
||||||
///
|
///
|
||||||
/// impl Serialize for E {
|
/// impl Serialize for E {
|
||||||
@@ -1991,7 +1995,11 @@ pub trait SerializeStruct {
|
|||||||
/// S: Serializer,
|
/// S: Serializer,
|
||||||
/// {
|
/// {
|
||||||
/// match *self {
|
/// match *self {
|
||||||
/// E::S { ref r, ref g, ref b } => {
|
/// E::S {
|
||||||
|
/// ref r,
|
||||||
|
/// ref g,
|
||||||
|
/// ref b,
|
||||||
|
/// } => {
|
||||||
/// let mut sv = serializer.serialize_struct_variant("E", 0, "S", 3)?;
|
/// let mut sv = serializer.serialize_struct_variant("E", 0, "S", 3)?;
|
||||||
/// sv.serialize_field("r", r)?;
|
/// sv.serialize_field("r", r)?;
|
||||||
/// sv.serialize_field("g", g)?;
|
/// sv.serialize_field("g", g)?;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "serde_derive"
|
name = "serde_derive"
|
||||||
version = "1.0.71" # remember to update html_root_url
|
version = "1.0.72" # remember to update html_root_url
|
||||||
authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>", "David Tolnay <dtolnay@gmail.com>"]
|
authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>", "David Tolnay <dtolnay@gmail.com>"]
|
||||||
license = "MIT/Apache-2.0"
|
license = "MIT/Apache-2.0"
|
||||||
description = "Macros 1.1 implementation of #[derive(Serialize, Deserialize)]"
|
description = "Macros 1.1 implementation of #[derive(Serialize, Deserialize)]"
|
||||||
@@ -13,6 +13,7 @@ include = ["Cargo.toml", "src/**/*.rs", "crates-io.md", "README.md", "LICENSE-AP
|
|||||||
|
|
||||||
[badges]
|
[badges]
|
||||||
travis-ci = { repository = "serde-rs/serde" }
|
travis-ci = { repository = "serde-rs/serde" }
|
||||||
|
appveyor = { repository = "serde-rs/serde" }
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = []
|
default = []
|
||||||
|
|||||||
@@ -90,7 +90,8 @@ pub fn with_where_predicates_from_variants(
|
|||||||
// Puts the given bound on any generic type parameters that are used in fields
|
// Puts the given bound on any generic type parameters that are used in fields
|
||||||
// for which filter returns true.
|
// for which filter returns true.
|
||||||
//
|
//
|
||||||
// For example, the following struct needs the bound `A: Serialize, B: Serialize`.
|
// For example, the following struct needs the bound `A: Serialize, B:
|
||||||
|
// Serialize`.
|
||||||
//
|
//
|
||||||
// struct S<'b, A, B: 'b, C> {
|
// struct S<'b, A, B: 'b, C> {
|
||||||
// a: A,
|
// a: A,
|
||||||
|
|||||||
@@ -837,7 +837,8 @@ fn deserialize_newtype_struct(
|
|||||||
|
|
||||||
#[cfg(feature = "deserialize_in_place")]
|
#[cfg(feature = "deserialize_in_place")]
|
||||||
fn deserialize_newtype_struct_in_place(params: &Parameters, field: &Field) -> TokenStream {
|
fn deserialize_newtype_struct_in_place(params: &Parameters, field: &Field) -> TokenStream {
|
||||||
// We do not generate deserialize_in_place if every field has a deserialize_with.
|
// We do not generate deserialize_in_place if every field has a
|
||||||
|
// deserialize_with.
|
||||||
assert!(field.attrs.deserialize_with().is_none());
|
assert!(field.attrs.deserialize_with().is_none());
|
||||||
|
|
||||||
let delife = params.borrowed.de_lifetime();
|
let delife = params.borrowed.de_lifetime();
|
||||||
@@ -941,8 +942,8 @@ fn deserialize_struct(
|
|||||||
quote!(mut __seq)
|
quote!(mut __seq)
|
||||||
};
|
};
|
||||||
|
|
||||||
// untagged struct variants do not get a visit_seq method. The same applies to structs that
|
// untagged struct variants do not get a visit_seq method. The same applies to
|
||||||
// only have a map representation.
|
// structs that only have a map representation.
|
||||||
let visit_seq = match *untagged {
|
let visit_seq = match *untagged {
|
||||||
Untagged::No if !cattrs.has_flatten() => Some(quote! {
|
Untagged::No if !cattrs.has_flatten() => Some(quote! {
|
||||||
#[inline]
|
#[inline]
|
||||||
@@ -2547,7 +2548,8 @@ fn deserialize_map_in_place(
|
|||||||
.map(|(i, field)| (field, field_i(i)))
|
.map(|(i, field)| (field, field_i(i)))
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
// For deserialize_in_place, declare booleans for each field that will be deserialized.
|
// For deserialize_in_place, declare booleans for each field that will be
|
||||||
|
// deserialized.
|
||||||
let let_flags = fields_names
|
let let_flags = fields_names
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|&&(field, _)| !field.attrs.skip_deserializing())
|
.filter(|&&(field, _)| !field.attrs.skip_deserializing())
|
||||||
|
|||||||
@@ -272,7 +272,7 @@ impl Container {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse `#[serde(bound = "D: Serialize")]`
|
// Parse `#[serde(bound = "T: SomeBound")]`
|
||||||
Meta(NameValue(ref m)) if m.ident == "bound" => {
|
Meta(NameValue(ref m)) if m.ident == "bound" => {
|
||||||
if let Ok(where_predicates) =
|
if let Ok(where_predicates) =
|
||||||
parse_lit_into_where(cx, &m.ident, &m.ident, &m.lit)
|
parse_lit_into_where(cx, &m.ident, &m.ident, &m.lit)
|
||||||
@@ -282,7 +282,7 @@ impl Container {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse `#[serde(bound(serialize = "D: Serialize", deserialize = "D: Deserialize"))]`
|
// Parse `#[serde(bound(serialize = "...", deserialize = "..."))]`
|
||||||
Meta(List(ref m)) if m.ident == "bound" => {
|
Meta(List(ref m)) if m.ident == "bound" => {
|
||||||
if let Ok((ser, de)) = get_where_predicates(cx, &m.nested) {
|
if let Ok((ser, de)) = get_where_predicates(cx, &m.nested) {
|
||||||
ser_bound.set_opt(ser);
|
ser_bound.set_opt(ser);
|
||||||
@@ -617,7 +617,7 @@ impl Variant {
|
|||||||
other.set_true();
|
other.set_true();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse `#[serde(bound = "D: Serialize")]`
|
// Parse `#[serde(bound = "T: SomeBound")]`
|
||||||
Meta(NameValue(ref m)) if m.ident == "bound" => {
|
Meta(NameValue(ref m)) if m.ident == "bound" => {
|
||||||
if let Ok(where_predicates) =
|
if let Ok(where_predicates) =
|
||||||
parse_lit_into_where(cx, &m.ident, &m.ident, &m.lit)
|
parse_lit_into_where(cx, &m.ident, &m.ident, &m.lit)
|
||||||
@@ -627,7 +627,7 @@ impl Variant {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse `#[serde(bound(serialize = "D: Serialize", deserialize = "D: Deserialize"))]`
|
// Parse `#[serde(bound(serialize = "...", deserialize = "..."))]`
|
||||||
Meta(List(ref m)) if m.ident == "bound" => {
|
Meta(List(ref m)) if m.ident == "bound" => {
|
||||||
if let Ok((ser, de)) = get_where_predicates(cx, &m.nested) {
|
if let Ok((ser, de)) = get_where_predicates(cx, &m.nested) {
|
||||||
ser_bound.set_opt(ser);
|
ser_bound.set_opt(ser);
|
||||||
@@ -921,7 +921,7 @@ impl Field {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse `#[serde(bound = "D: Serialize")]`
|
// Parse `#[serde(bound = "T: SomeBound")]`
|
||||||
Meta(NameValue(ref m)) if m.ident == "bound" => {
|
Meta(NameValue(ref m)) if m.ident == "bound" => {
|
||||||
if let Ok(where_predicates) =
|
if let Ok(where_predicates) =
|
||||||
parse_lit_into_where(cx, &m.ident, &m.ident, &m.lit)
|
parse_lit_into_where(cx, &m.ident, &m.ident, &m.lit)
|
||||||
@@ -931,7 +931,7 @@ impl Field {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse `#[serde(bound(serialize = "D: Serialize", deserialize = "D: Deserialize"))]`
|
// Parse `#[serde(bound(serialize = "...", deserialize = "..."))]`
|
||||||
Meta(List(ref m)) if m.ident == "bound" => {
|
Meta(List(ref m)) if m.ident == "bound" => {
|
||||||
if let Ok((ser, de)) = get_where_predicates(cx, &m.nested) {
|
if let Ok((ser, de)) = get_where_predicates(cx, &m.nested) {
|
||||||
ser_bound.set_opt(ser);
|
ser_bound.set_opt(ser);
|
||||||
@@ -989,9 +989,9 @@ impl Field {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Is skip_deserializing, initialize the field to Default::default() unless a different
|
// Is skip_deserializing, initialize the field to Default::default() unless a
|
||||||
// default is specified by `#[serde(default = "...")]` on ourselves or our container (e.g.
|
// different default is specified by `#[serde(default = "...")]` on
|
||||||
// the struct we are in).
|
// ourselves or our container (e.g. the struct we are in).
|
||||||
if let Default::None = *container_default {
|
if let Default::None = *container_default {
|
||||||
if skip_deserializing.0.value.is_some() {
|
if skip_deserializing.0.value.is_some() {
|
||||||
default.set_if_none(Default::Default);
|
default.set_if_none(Default::Default);
|
||||||
|
|||||||
@@ -22,13 +22,16 @@ pub enum RenameRule {
|
|||||||
LowerCase,
|
LowerCase,
|
||||||
/// Rename direct children to "UPPERCASE" style.
|
/// Rename direct children to "UPPERCASE" style.
|
||||||
UPPERCASE,
|
UPPERCASE,
|
||||||
/// Rename direct children to "PascalCase" style, as typically used for enum variants.
|
/// Rename direct children to "PascalCase" style, as typically used for
|
||||||
|
/// enum variants.
|
||||||
PascalCase,
|
PascalCase,
|
||||||
/// Rename direct children to "camelCase" style.
|
/// Rename direct children to "camelCase" style.
|
||||||
CamelCase,
|
CamelCase,
|
||||||
/// Rename direct children to "snake_case" style, as commonly used for fields.
|
/// Rename direct children to "snake_case" style, as commonly used for
|
||||||
|
/// fields.
|
||||||
SnakeCase,
|
SnakeCase,
|
||||||
/// Rename direct children to "SCREAMING_SNAKE_CASE" style, as commonly used for constants.
|
/// Rename direct children to "SCREAMING_SNAKE_CASE" style, as commonly
|
||||||
|
/// used for constants.
|
||||||
ScreamingSnakeCase,
|
ScreamingSnakeCase,
|
||||||
/// Rename direct children to "kebab-case" style.
|
/// Rename direct children to "kebab-case" style.
|
||||||
KebabCase,
|
KebabCase,
|
||||||
|
|||||||
@@ -22,7 +22,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.71")]
|
#![doc(html_root_url = "https://docs.rs/serde_derive/1.0.72")]
|
||||||
#![cfg_attr(feature = "cargo-clippy", deny(clippy, clippy_pedantic))]
|
#![cfg_attr(feature = "cargo-clippy", deny(clippy, clippy_pedantic))]
|
||||||
// Whitelisted clippy lints
|
// Whitelisted clippy lints
|
||||||
#![cfg_attr(
|
#![cfg_attr(
|
||||||
|
|||||||
@@ -20,3 +20,4 @@ syn = { version = "0.14", default-features = false, features = ["derive", "parsi
|
|||||||
|
|
||||||
[badges]
|
[badges]
|
||||||
travis-ci = { repository = "serde-rs/serde" }
|
travis-ci = { repository = "serde-rs/serde" }
|
||||||
|
appveyor = { repository = "serde-rs/serde" }
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "serde_test"
|
name = "serde_test"
|
||||||
version = "1.0.71" # remember to update html_root_url
|
version = "1.0.72" # remember to update html_root_url
|
||||||
authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>", "David Tolnay <dtolnay@gmail.com>"]
|
authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>", "David Tolnay <dtolnay@gmail.com>"]
|
||||||
license = "MIT/Apache-2.0"
|
license = "MIT/Apache-2.0"
|
||||||
description = "Token De/Serializer for testing De/Serialize implementations"
|
description = "Token De/Serializer for testing De/Serialize implementations"
|
||||||
@@ -20,3 +20,4 @@ serde_derive = { version = "1.0", path = "../serde_derive" }
|
|||||||
|
|
||||||
[badges]
|
[badges]
|
||||||
travis-ci = { repository = "serde-rs/serde" }
|
travis-ci = { repository = "serde-rs/serde" }
|
||||||
|
appveyor = { repository = "serde-rs/serde" }
|
||||||
|
|||||||
@@ -95,7 +95,8 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Asserts that `value` serializes to the given `tokens`, and then yields `error`.
|
/// Asserts that `value` serializes to the given `tokens`, and then yields
|
||||||
|
/// `error`.
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # #[macro_use]
|
/// # #[macro_use]
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ pub struct Compact<T: ?Sized>(T);
|
|||||||
/// extern crate serde_test;
|
/// extern crate serde_test;
|
||||||
///
|
///
|
||||||
/// use serde::{Deserialize, Deserializer, Serialize, Serializer};
|
/// use serde::{Deserialize, Deserializer, Serialize, Serializer};
|
||||||
/// use serde_test::{Configure, Token, assert_tokens};
|
/// use serde_test::{assert_tokens, Configure, Token};
|
||||||
///
|
///
|
||||||
/// #[derive(Debug, PartialEq)]
|
/// #[derive(Debug, PartialEq)]
|
||||||
/// struct Example(u8, u8);
|
/// struct Example(u8, u8);
|
||||||
@@ -67,12 +67,7 @@ pub struct Compact<T: ?Sized>(T);
|
|||||||
/// Token::TupleEnd,
|
/// Token::TupleEnd,
|
||||||
/// ],
|
/// ],
|
||||||
/// );
|
/// );
|
||||||
/// assert_tokens(
|
/// assert_tokens(&Example(1, 0).readable(), &[Token::Str("1.0")]);
|
||||||
/// &Example(1, 0).readable(),
|
|
||||||
/// &[
|
|
||||||
/// Token::Str("1.0"),
|
|
||||||
/// ],
|
|
||||||
/// );
|
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
pub trait Configure {
|
pub trait Configure {
|
||||||
|
|||||||
@@ -161,7 +161,7 @@
|
|||||||
//! # }
|
//! # }
|
||||||
//! ```
|
//! ```
|
||||||
|
|
||||||
#![doc(html_root_url = "https://docs.rs/serde_test/1.0.71")]
|
#![doc(html_root_url = "https://docs.rs/serde_test/1.0.72")]
|
||||||
#![cfg_attr(feature = "cargo-clippy", deny(clippy, clippy_pedantic))]
|
#![cfg_attr(feature = "cargo-clippy", deny(clippy, clippy_pedantic))]
|
||||||
// Whitelisted clippy lints
|
// Whitelisted clippy lints
|
||||||
#![cfg_attr(feature = "cargo-clippy", allow(float_cmp))]
|
#![cfg_attr(feature = "cargo-clippy", allow(float_cmp))]
|
||||||
|
|||||||
@@ -11,7 +11,8 @@ use serde::{ser, Serialize};
|
|||||||
use error::Error;
|
use error::Error;
|
||||||
use token::Token;
|
use token::Token;
|
||||||
|
|
||||||
/// A `Serializer` that ensures that a value serializes to a given list of tokens.
|
/// A `Serializer` that ensures that a value serializes to a given list of
|
||||||
|
/// tokens.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Serializer<'a> {
|
pub struct Serializer<'a> {
|
||||||
tokens: &'a [Token],
|
tokens: &'a [Token],
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
// option. This file may not be copied, modified, or distributed
|
// option. This file may not be copied, modified, or distributed
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
// These just test that serde_codegen is able to produce code that compiles
|
// These just test that serde_derive is able to produce code that compiles
|
||||||
// successfully when there are a variety of generics and non-(de)serializable
|
// successfully when there are a variety of generics and non-(de)serializable
|
||||||
// types involved.
|
// types involved.
|
||||||
|
|
||||||
@@ -198,12 +198,10 @@ fn test_gen() {
|
|||||||
assert::<WithTraits1<X, X>>();
|
assert::<WithTraits1<X, X>>();
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Serialize, Deserialize)]
|
||||||
#[serde(
|
#[serde(bound(
|
||||||
bound(
|
serialize = "D: SerializeWith",
|
||||||
serialize = "D: SerializeWith",
|
deserialize = "D: DeserializeWith"
|
||||||
deserialize = "D: DeserializeWith"
|
))]
|
||||||
)
|
|
||||||
)]
|
|
||||||
struct WithTraits2<D, E> {
|
struct WithTraits2<D, E> {
|
||||||
#[serde(
|
#[serde(
|
||||||
serialize_with = "SerializeWith::serialize_with",
|
serialize_with = "SerializeWith::serialize_with",
|
||||||
@@ -240,12 +238,10 @@ fn test_gen() {
|
|||||||
assert::<VariantWithTraits1<X, X>>();
|
assert::<VariantWithTraits1<X, X>>();
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Serialize, Deserialize)]
|
||||||
#[serde(
|
#[serde(bound(
|
||||||
bound(
|
serialize = "D: SerializeWith",
|
||||||
serialize = "D: SerializeWith",
|
deserialize = "D: DeserializeWith"
|
||||||
deserialize = "D: DeserializeWith"
|
))]
|
||||||
)
|
|
||||||
)]
|
|
||||||
enum VariantWithTraits2<D, E> {
|
enum VariantWithTraits2<D, E> {
|
||||||
#[serde(
|
#[serde(
|
||||||
serialize_with = "SerializeWith::serialize_with",
|
serialize_with = "SerializeWith::serialize_with",
|
||||||
@@ -669,6 +665,19 @@ fn test_gen() {
|
|||||||
#[serde(deserialize_with = "de_x")]
|
#[serde(deserialize_with = "de_x")]
|
||||||
x: X,
|
x: X,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Deserialize)]
|
||||||
|
#[serde(untagged)]
|
||||||
|
enum UntaggedWithBorrow<'a> {
|
||||||
|
Single(#[serde(borrow)] RelObject<'a>),
|
||||||
|
Many(#[serde(borrow)] Vec<RelObject<'a>>),
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Deserialize)]
|
||||||
|
struct RelObject<'a> {
|
||||||
|
ty: &'a str,
|
||||||
|
id: String,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
|
|||||||
Reference in New Issue
Block a user