mirror of
https://github.com/pezkuwichain/serde.git
synced 2026-06-20 06:51:12 +00:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| af31449cb1 | |||
| 1afae183b0 |
@@ -5,9 +5,6 @@ on:
|
|||||||
pull_request:
|
pull_request:
|
||||||
schedule: [cron: "40 1 * * *"]
|
schedule: [cron: "40 1 * * *"]
|
||||||
|
|
||||||
permissions:
|
|
||||||
contents: read
|
|
||||||
|
|
||||||
env:
|
env:
|
||||||
RUSTFLAGS: -Dwarnings
|
RUSTFLAGS: -Dwarnings
|
||||||
|
|
||||||
@@ -79,7 +76,7 @@ jobs:
|
|||||||
- uses: dtolnay/rust-toolchain@1.13.0
|
- uses: dtolnay/rust-toolchain@1.13.0
|
||||||
- name: Get timestamp for cache
|
- name: Get timestamp for cache
|
||||||
id: date
|
id: date
|
||||||
run: echo yearmo=$(date +%Y%m) >> $GITHUB_OUTPUT
|
run: echo ::set-output name=yearmo::$(date +%Y%m)
|
||||||
- uses: actions/cache@v1
|
- uses: actions/cache@v1
|
||||||
with:
|
with:
|
||||||
path: ~/.cargo/registry/index
|
path: ~/.cargo/registry/index
|
||||||
@@ -167,11 +164,11 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
- uses: dtolnay/rust-toolchain@clippy
|
- uses: dtolnay/rust-toolchain@clippy
|
||||||
- run: cd serde && cargo clippy --features rc,unstable -- -Dclippy::all -Dclippy::pedantic -Aclippy::let_underscore_drop
|
- run: cd serde && cargo clippy --features rc,unstable -- -Dclippy::all -Dclippy::pedantic
|
||||||
- run: cd serde_derive && cargo clippy -- -Dclippy::all -Dclippy::pedantic
|
- run: cd serde_derive && cargo clippy -- -Dclippy::all -Dclippy::pedantic
|
||||||
- run: cd serde_derive_internals && cargo clippy -- -Dclippy::all -Dclippy::pedantic
|
- run: cd serde_derive_internals && cargo clippy -- -Dclippy::all -Dclippy::pedantic
|
||||||
- run: cd serde_test && cargo clippy -- -Dclippy::all -Dclippy::pedantic -Aclippy::let_underscore_drop
|
- run: cd serde_test && cargo clippy -- -Dclippy::all -Dclippy::pedantic
|
||||||
- run: cd test_suite && cargo clippy --tests --features unstable -- -Dclippy::all -Dclippy::pedantic -Aclippy::let_underscore_drop
|
- run: cd test_suite && cargo clippy --tests --features unstable -- -Dclippy::all -Dclippy::pedantic
|
||||||
- run: cd test_suite/no_std && cargo clippy -- -Dclippy::all -Dclippy::pedantic
|
- run: cd test_suite/no_std && cargo clippy -- -Dclippy::all -Dclippy::pedantic
|
||||||
|
|
||||||
miri:
|
miri:
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
[workspace]
|
[workspace]
|
||||||
members = [
|
members = [
|
||||||
"serde",
|
"serde",
|
||||||
"serde_derive",
|
|
||||||
"serde_derive_internals",
|
"serde_derive_internals",
|
||||||
"serde_test",
|
"serde_test",
|
||||||
"test_suite",
|
"test_suite",
|
||||||
|
|||||||
+12
-12
@@ -1,21 +1,21 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "serde"
|
name = "serde"
|
||||||
version = "1.0.146" # remember to update html_root_url and serde_derive dependency
|
version = "1.0.137" # 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"
|
|
||||||
categories = ["encoding", "no-std"]
|
|
||||||
description = "A generic serialization/deserialization framework"
|
|
||||||
documentation = "https://docs.serde.rs/serde/"
|
|
||||||
homepage = "https://serde.rs"
|
|
||||||
include = ["build.rs", "src/**/*.rs", "crates-io.md", "README.md", "LICENSE-APACHE", "LICENSE-MIT"]
|
|
||||||
keywords = ["serde", "serialization", "no_std"]
|
|
||||||
license = "MIT OR Apache-2.0"
|
|
||||||
readme = "crates-io.md"
|
|
||||||
repository = "https://github.com/serde-rs/serde"
|
|
||||||
rust-version = "1.13"
|
rust-version = "1.13"
|
||||||
|
license = "MIT OR Apache-2.0"
|
||||||
|
description = "A generic serialization/deserialization framework"
|
||||||
|
homepage = "https://serde.rs"
|
||||||
|
repository = "https://github.com/serde-rs/serde"
|
||||||
|
documentation = "https://docs.serde.rs/serde/"
|
||||||
|
keywords = ["serde", "serialization", "no_std"]
|
||||||
|
categories = ["encoding"]
|
||||||
|
readme = "crates-io.md"
|
||||||
|
include = ["build.rs", "src/**/*.rs", "crates-io.md", "README.md", "LICENSE-APACHE", "LICENSE-MIT"]
|
||||||
|
build = "build.rs"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
serde_derive = { version = "=1.0.146", optional = true, path = "../serde_derive" }
|
serde_derive = { version = "=1.0.137", 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" }
|
||||||
|
|||||||
@@ -228,7 +228,7 @@ impl<'de> Visitor<'de> for IgnoredAny {
|
|||||||
where
|
where
|
||||||
A: EnumAccess<'de>,
|
A: EnumAccess<'de>,
|
||||||
{
|
{
|
||||||
try!(data.variant::<IgnoredAny>()).1.newtype_variant()
|
data.variant::<IgnoredAny>()?.1.newtype_variant()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2268,14 +2268,14 @@ where
|
|||||||
where
|
where
|
||||||
D: Deserializer<'de>,
|
D: Deserializer<'de>,
|
||||||
{
|
{
|
||||||
let (start, end) = try!(deserializer.deserialize_struct(
|
let (start, end) = deserializer.deserialize_struct(
|
||||||
"Range",
|
"Range",
|
||||||
range::FIELDS,
|
range::FIELDS,
|
||||||
range::RangeVisitor {
|
range::RangeVisitor {
|
||||||
expecting: "struct Range",
|
expecting: "struct Range",
|
||||||
phantom: PhantomData,
|
phantom: PhantomData,
|
||||||
},
|
},
|
||||||
));
|
)?;
|
||||||
Ok(start..end)
|
Ok(start..end)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2289,14 +2289,14 @@ where
|
|||||||
where
|
where
|
||||||
D: Deserializer<'de>,
|
D: Deserializer<'de>,
|
||||||
{
|
{
|
||||||
let (start, end) = try!(deserializer.deserialize_struct(
|
let (start, end) = deserializer.deserialize_struct(
|
||||||
"RangeInclusive",
|
"RangeInclusive",
|
||||||
range::FIELDS,
|
range::FIELDS,
|
||||||
range::RangeVisitor {
|
range::RangeVisitor {
|
||||||
expecting: "struct RangeInclusive",
|
expecting: "struct RangeInclusive",
|
||||||
phantom: PhantomData,
|
phantom: PhantomData,
|
||||||
},
|
},
|
||||||
));
|
)?;
|
||||||
Ok(RangeInclusive::new(start, end))
|
Ok(RangeInclusive::new(start, end))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+12
-17
@@ -30,7 +30,7 @@
|
|||||||
//! # The Deserializer trait
|
//! # The Deserializer trait
|
||||||
//!
|
//!
|
||||||
//! [`Deserializer`] implementations are provided by third-party crates, for
|
//! [`Deserializer`] implementations are provided by third-party crates, for
|
||||||
//! example [`serde_json`], [`serde_yaml`] and [`postcard`].
|
//! example [`serde_json`], [`serde_yaml`] and [`bincode`].
|
||||||
//!
|
//!
|
||||||
//! A partial list of well-maintained formats is given on the [Serde
|
//! A partial list of well-maintained formats is given on the [Serde
|
||||||
//! website][data formats].
|
//! website][data formats].
|
||||||
@@ -104,7 +104,7 @@
|
|||||||
//! [`Deserialize`]: ../trait.Deserialize.html
|
//! [`Deserialize`]: ../trait.Deserialize.html
|
||||||
//! [`Deserializer`]: ../trait.Deserializer.html
|
//! [`Deserializer`]: ../trait.Deserializer.html
|
||||||
//! [`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
|
||||||
//! [`postcard`]: https://github.com/jamesmunns/postcard
|
//! [`bincode`]: https://github.com/bincode-org/bincode
|
||||||
//! [`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
|
||||||
//! [`serde_json`]: https://github.com/serde-rs/json
|
//! [`serde_json`]: https://github.com/serde-rs/json
|
||||||
@@ -565,7 +565,7 @@ pub trait Deserialize<'de>: Sized {
|
|||||||
D: Deserializer<'de>,
|
D: Deserializer<'de>,
|
||||||
{
|
{
|
||||||
// Default implementation just delegates to `deserialize` impl.
|
// Default implementation just delegates to `deserialize` impl.
|
||||||
*place = try!(Deserialize::deserialize(deserializer));
|
*place = Deserialize::deserialize(deserializer)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -708,11 +708,6 @@ impl<T> DeserializeOwned for T where T: for<'de> Deserialize<'de> {}
|
|||||||
/// where
|
/// where
|
||||||
/// A: SeqAccess<'de>,
|
/// A: SeqAccess<'de>,
|
||||||
/// {
|
/// {
|
||||||
/// // Decrease the number of reallocations if there are many elements
|
|
||||||
/// if let Some(size_hint) = seq.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
|
||||||
/// // the existing vector.
|
/// // the existing vector.
|
||||||
/// while let Some(elem) = seq.next_element()? {
|
/// while let Some(elem) = seq.next_element()? {
|
||||||
@@ -862,10 +857,10 @@ where
|
|||||||
/// The `Deserializer` trait supports two entry point styles which enables
|
/// The `Deserializer` trait supports two entry point styles which enables
|
||||||
/// different kinds of deserialization.
|
/// different kinds of deserialization.
|
||||||
///
|
///
|
||||||
/// 1. The `deserialize_any` method. Self-describing data formats like JSON are
|
/// 1. The `deserialize` method. Self-describing data formats like JSON are able
|
||||||
/// able to look at the serialized data and tell what it represents. For
|
/// to look at the serialized data and tell what it represents. For example
|
||||||
/// example the JSON deserializer may see an opening curly brace (`{`) and
|
/// the JSON deserializer may see an opening curly brace (`{`) and know that
|
||||||
/// know that it is seeing a map. If the data format supports
|
/// it is seeing a map. If the data format supports
|
||||||
/// `Deserializer::deserialize_any`, it will drive the Visitor using whatever
|
/// `Deserializer::deserialize_any`, it will drive the Visitor using whatever
|
||||||
/// 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
|
||||||
@@ -874,7 +869,7 @@ where
|
|||||||
/// `Deserializer::deserialize_any`.
|
/// `Deserializer::deserialize_any`.
|
||||||
///
|
///
|
||||||
/// 2. The various `deserialize_*` methods. Non-self-describing formats like
|
/// 2. The various `deserialize_*` methods. Non-self-describing formats like
|
||||||
/// Postcard 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.
|
||||||
/// The `deserialize_*` methods are hints to the deserializer for how to
|
/// The `deserialize_*` methods are hints to the deserializer for how to
|
||||||
/// interpret the next piece of input. Non-self-describing formats are not
|
/// interpret the next piece of input. Non-self-describing formats are not
|
||||||
/// able to deserialize something like `serde_json::Value` which relies on
|
/// able to deserialize something like `serde_json::Value` which relies on
|
||||||
@@ -884,7 +879,7 @@ where
|
|||||||
/// `Deserializer::deserialize_any` unless you need to be told by the
|
/// `Deserializer::deserialize_any` unless you need to be told by the
|
||||||
/// Deserializer what type is in the input. Know that relying on
|
/// Deserializer what type is in the input. Know that relying on
|
||||||
/// `Deserializer::deserialize_any` means your data type will be able to
|
/// `Deserializer::deserialize_any` means your data type will be able to
|
||||||
/// deserialize from self-describing formats only, ruling out Postcard and many
|
/// deserialize from self-describing formats only, ruling out Bincode and many
|
||||||
/// others.
|
/// others.
|
||||||
///
|
///
|
||||||
/// [Serde data model]: https://serde.rs/data-model.html
|
/// [Serde data model]: https://serde.rs/data-model.html
|
||||||
@@ -915,7 +910,7 @@ pub trait Deserializer<'de>: Sized {
|
|||||||
/// `Deserializer::deserialize_any` unless you need to be told by the
|
/// `Deserializer::deserialize_any` unless you need to be told by the
|
||||||
/// Deserializer what type is in the input. Know that relying on
|
/// Deserializer what type is in the input. Know that relying on
|
||||||
/// `Deserializer::deserialize_any` means your data type will be able to
|
/// `Deserializer::deserialize_any` means your data type will be able to
|
||||||
/// deserialize from self-describing formats only, ruling out Postcard and
|
/// deserialize from self-describing formats only, ruling out Bincode and
|
||||||
/// many others.
|
/// many others.
|
||||||
fn deserialize_any<V>(self, visitor: V) -> Result<V::Value, Self::Error>
|
fn deserialize_any<V>(self, visitor: V) -> Result<V::Value, Self::Error>
|
||||||
where
|
where
|
||||||
@@ -1156,7 +1151,7 @@ pub trait Deserializer<'de>: Sized {
|
|||||||
/// Some types have a human-readable form that may be somewhat expensive to
|
/// Some types have a human-readable form that may be somewhat expensive to
|
||||||
/// construct, as well as a binary form that is compact and efficient.
|
/// construct, as well as a binary form that is compact and efficient.
|
||||||
/// Generally text-based formats like JSON and YAML will prefer to use the
|
/// Generally text-based formats like JSON and YAML will prefer to use the
|
||||||
/// human-readable one and binary formats like Postcard will prefer the
|
/// human-readable one and binary formats like Bincode will prefer the
|
||||||
/// compact one.
|
/// compact one.
|
||||||
///
|
///
|
||||||
/// ```edition2018
|
/// ```edition2018
|
||||||
@@ -1560,7 +1555,7 @@ pub trait Visitor<'de>: Sized {
|
|||||||
/// `Deserializer`.
|
/// `Deserializer`.
|
||||||
///
|
///
|
||||||
/// This enables zero-copy deserialization of bytes in some formats. For
|
/// This enables zero-copy deserialization of bytes in some formats. For
|
||||||
/// example Postcard data containing bytes can be deserialized with zero
|
/// example Bincode data containing bytes can be deserialized with zero
|
||||||
/// copying into a `&'a [u8]` as long as the input data outlives `'a`.
|
/// copying into a `&'a [u8]` as long as the input data outlives `'a`.
|
||||||
///
|
///
|
||||||
/// The default implementation forwards to `visit_bytes`.
|
/// The default implementation forwards to `visit_bytes`.
|
||||||
|
|||||||
+9
-53
@@ -128,7 +128,9 @@ where
|
|||||||
type Deserializer = UnitDeserializer<E>;
|
type Deserializer = UnitDeserializer<E>;
|
||||||
|
|
||||||
fn into_deserializer(self) -> UnitDeserializer<E> {
|
fn into_deserializer(self) -> UnitDeserializer<E> {
|
||||||
UnitDeserializer::new()
|
UnitDeserializer {
|
||||||
|
marker: PhantomData,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -139,15 +141,6 @@ pub struct UnitDeserializer<E> {
|
|||||||
|
|
||||||
impl_copy_clone!(UnitDeserializer);
|
impl_copy_clone!(UnitDeserializer);
|
||||||
|
|
||||||
impl<E> UnitDeserializer<E> {
|
|
||||||
#[allow(missing_docs)]
|
|
||||||
pub fn new() -> Self {
|
|
||||||
UnitDeserializer {
|
|
||||||
marker: PhantomData,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'de, E> de::Deserializer<'de> for UnitDeserializer<E>
|
impl<'de, E> de::Deserializer<'de> for UnitDeserializer<E>
|
||||||
where
|
where
|
||||||
E: de::Error,
|
E: de::Error,
|
||||||
@@ -243,15 +236,8 @@ macro_rules! primitive_deserializer {
|
|||||||
type Deserializer = $name<E>;
|
type Deserializer = $name<E>;
|
||||||
|
|
||||||
fn into_deserializer(self) -> $name<E> {
|
fn into_deserializer(self) -> $name<E> {
|
||||||
$name::new(self)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<E> $name<E> {
|
|
||||||
#[allow(missing_docs)]
|
|
||||||
pub fn new(value: $ty) -> Self {
|
|
||||||
$name {
|
$name {
|
||||||
value: value,
|
value: self,
|
||||||
marker: PhantomData,
|
marker: PhantomData,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -322,15 +308,8 @@ where
|
|||||||
type Deserializer = U32Deserializer<E>;
|
type Deserializer = U32Deserializer<E>;
|
||||||
|
|
||||||
fn into_deserializer(self) -> U32Deserializer<E> {
|
fn into_deserializer(self) -> U32Deserializer<E> {
|
||||||
U32Deserializer::new(self)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<E> U32Deserializer<E> {
|
|
||||||
#[allow(missing_docs)]
|
|
||||||
pub fn new(value: u32) -> Self {
|
|
||||||
U32Deserializer {
|
U32Deserializer {
|
||||||
value: value,
|
value: self,
|
||||||
marker: PhantomData,
|
marker: PhantomData,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -411,15 +390,8 @@ where
|
|||||||
type Deserializer = StrDeserializer<'a, E>;
|
type Deserializer = StrDeserializer<'a, E>;
|
||||||
|
|
||||||
fn into_deserializer(self) -> StrDeserializer<'a, E> {
|
fn into_deserializer(self) -> StrDeserializer<'a, E> {
|
||||||
StrDeserializer::new(self)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a, E> StrDeserializer<'a, E> {
|
|
||||||
#[allow(missing_docs)]
|
|
||||||
pub fn new(value: &'a str) -> Self {
|
|
||||||
StrDeserializer {
|
StrDeserializer {
|
||||||
value: value,
|
value: self,
|
||||||
marker: PhantomData,
|
marker: PhantomData,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -589,16 +561,8 @@ where
|
|||||||
type Deserializer = StringDeserializer<E>;
|
type Deserializer = StringDeserializer<E>;
|
||||||
|
|
||||||
fn into_deserializer(self) -> StringDeserializer<E> {
|
fn into_deserializer(self) -> StringDeserializer<E> {
|
||||||
StringDeserializer::new(self)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(any(feature = "std", feature = "alloc"))]
|
|
||||||
impl<E> StringDeserializer<E> {
|
|
||||||
#[allow(missing_docs)]
|
|
||||||
pub fn new(value: String) -> Self {
|
|
||||||
StringDeserializer {
|
StringDeserializer {
|
||||||
value: value,
|
value: self,
|
||||||
marker: PhantomData,
|
marker: PhantomData,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -692,16 +656,8 @@ where
|
|||||||
type Deserializer = CowStrDeserializer<'a, E>;
|
type Deserializer = CowStrDeserializer<'a, E>;
|
||||||
|
|
||||||
fn into_deserializer(self) -> CowStrDeserializer<'a, E> {
|
fn into_deserializer(self) -> CowStrDeserializer<'a, E> {
|
||||||
CowStrDeserializer::new(self)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(any(feature = "std", feature = "alloc"))]
|
|
||||||
impl<'a, E> CowStrDeserializer<'a, E> {
|
|
||||||
#[allow(missing_docs)]
|
|
||||||
pub fn new(value: Cow<'a, str>) -> Self {
|
|
||||||
CowStrDeserializer {
|
CowStrDeserializer {
|
||||||
value: value,
|
value: self,
|
||||||
marker: PhantomData,
|
marker: PhantomData,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1501,7 +1457,7 @@ where
|
|||||||
where
|
where
|
||||||
T: de::DeserializeSeed<'de>,
|
T: de::DeserializeSeed<'de>,
|
||||||
{
|
{
|
||||||
match try!(self.map.next_key_seed(seed)) {
|
match self.map.next_key_seed(seed)? {
|
||||||
Some(key) => Ok((key, private::map_as_enum(self.map))),
|
Some(key) => Ok((key, private::map_as_enum(self.map))),
|
||||||
None => Err(de::Error::invalid_type(de::Unexpected::Map, &"enum")),
|
None => Err(de::Error::invalid_type(de::Unexpected::Map, &"enum")),
|
||||||
}
|
}
|
||||||
|
|||||||
+7
-19
@@ -31,7 +31,8 @@
|
|||||||
//! for Serde by the community.
|
//! for Serde by the community.
|
||||||
//!
|
//!
|
||||||
//! - [JSON], the ubiquitous JavaScript Object Notation used by many HTTP APIs.
|
//! - [JSON], the ubiquitous JavaScript Object Notation used by many HTTP APIs.
|
||||||
//! - [Postcard], a no\_std and embedded-systems friendly compact binary format.
|
//! - [Bincode], a compact binary format
|
||||||
|
//! used for IPC within the Servo rendering engine.
|
||||||
//! - [CBOR], a Concise Binary Object Representation designed for small message
|
//! - [CBOR], a Concise Binary Object Representation designed for small message
|
||||||
//! size without the need for version negotiation.
|
//! size without the need for version negotiation.
|
||||||
//! - [YAML], a self-proclaimed human-friendly configuration language that ain't
|
//! - [YAML], a self-proclaimed human-friendly configuration language that ain't
|
||||||
@@ -44,6 +45,7 @@
|
|||||||
//! - [Avro], a binary format used within Apache Hadoop, with support for schema
|
//! - [Avro], a binary format used within Apache Hadoop, with support for schema
|
||||||
//! definition.
|
//! definition.
|
||||||
//! - [JSON5], a superset of JSON including some productions from ES5.
|
//! - [JSON5], a superset of JSON including some productions from ES5.
|
||||||
|
//! - [Postcard], a no\_std and embedded-systems friendly compact binary format.
|
||||||
//! - [URL] query strings, in the x-www-form-urlencoded format.
|
//! - [URL] query strings, in the x-www-form-urlencoded format.
|
||||||
//! - [Envy], a way to deserialize environment variables into Rust structs.
|
//! - [Envy], a way to deserialize environment variables into Rust structs.
|
||||||
//! *(deserialization only)*
|
//! *(deserialization only)*
|
||||||
@@ -57,7 +59,7 @@
|
|||||||
//! and from DynamoDB.
|
//! and from DynamoDB.
|
||||||
//!
|
//!
|
||||||
//! [JSON]: https://github.com/serde-rs/json
|
//! [JSON]: https://github.com/serde-rs/json
|
||||||
//! [Postcard]: https://github.com/jamesmunns/postcard
|
//! [Bincode]: https://github.com/bincode-org/bincode
|
||||||
//! [CBOR]: https://github.com/enarx/ciborium
|
//! [CBOR]: https://github.com/enarx/ciborium
|
||||||
//! [YAML]: https://github.com/dtolnay/serde-yaml
|
//! [YAML]: https://github.com/dtolnay/serde-yaml
|
||||||
//! [MessagePack]: https://github.com/3Hren/msgpack-rust
|
//! [MessagePack]: https://github.com/3Hren/msgpack-rust
|
||||||
@@ -65,8 +67,9 @@
|
|||||||
//! [Pickle]: https://github.com/birkenfeld/serde-pickle
|
//! [Pickle]: https://github.com/birkenfeld/serde-pickle
|
||||||
//! [RON]: https://github.com/ron-rs/ron
|
//! [RON]: https://github.com/ron-rs/ron
|
||||||
//! [BSON]: https://github.com/mongodb/bson-rust
|
//! [BSON]: https://github.com/mongodb/bson-rust
|
||||||
//! [Avro]: https://docs.rs/apache-avro
|
//! [Avro]: https://github.com/flavray/avro-rs
|
||||||
//! [JSON5]: https://github.com/callum-oakley/json5-rs
|
//! [JSON5]: https://github.com/callum-oakley/json5-rs
|
||||||
|
//! [Postcard]: https://github.com/jamesmunns/postcard
|
||||||
//! [URL]: https://docs.rs/serde_qs
|
//! [URL]: https://docs.rs/serde_qs
|
||||||
//! [Envy]: https://github.com/softprops/envy
|
//! [Envy]: https://github.com/softprops/envy
|
||||||
//! [Envy Store]: https://github.com/softprops/envy-store
|
//! [Envy Store]: https://github.com/softprops/envy-store
|
||||||
@@ -81,7 +84,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.146")]
|
#![doc(html_root_url = "https://docs.rs/serde/1.0.137")]
|
||||||
// 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
|
||||||
@@ -117,10 +120,8 @@
|
|||||||
// correctly used
|
// correctly used
|
||||||
derive_partial_eq_without_eq,
|
derive_partial_eq_without_eq,
|
||||||
enum_glob_use,
|
enum_glob_use,
|
||||||
explicit_auto_deref,
|
|
||||||
let_underscore_drop,
|
let_underscore_drop,
|
||||||
map_err_ignore,
|
map_err_ignore,
|
||||||
new_without_default,
|
|
||||||
result_unit_err,
|
result_unit_err,
|
||||||
wildcard_imports,
|
wildcard_imports,
|
||||||
// not practical
|
// not practical
|
||||||
@@ -249,19 +250,6 @@ mod lib {
|
|||||||
pub use self::core::time::Duration;
|
pub use self::core::time::Duration;
|
||||||
}
|
}
|
||||||
|
|
||||||
// None of this crate's error handling needs the `From::from` error conversion
|
|
||||||
// performed implicitly by the `?` operator or the standard library's `try!`
|
|
||||||
// macro. This simplified macro gives a 5.5% improvement in compile time
|
|
||||||
// compared to standard `try!`, and 9% improvement compared to `?`.
|
|
||||||
macro_rules! try {
|
|
||||||
($expr:expr) => {
|
|
||||||
match $expr {
|
|
||||||
Ok(val) => val,
|
|
||||||
Err(err) => return Err(err),
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
|
|||||||
@@ -1262,17 +1262,6 @@ mod content {
|
|||||||
{
|
{
|
||||||
match self.content {
|
match self.content {
|
||||||
Content::Unit => visitor.visit_unit(),
|
Content::Unit => visitor.visit_unit(),
|
||||||
|
|
||||||
// Allow deserializing newtype variant containing unit.
|
|
||||||
//
|
|
||||||
// #[derive(Deserialize)]
|
|
||||||
// #[serde(tag = "result")]
|
|
||||||
// enum Response<T> {
|
|
||||||
// Success(T),
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// We want {"result":"Success"} to deserialize into Response<()>.
|
|
||||||
Content::Map(ref v) if v.is_empty() => visitor.visit_unit(),
|
|
||||||
_ => Err(self.invalid_type(&visitor)),
|
_ => Err(self.invalid_type(&visitor)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,6 +51,7 @@ enum Unsupported {
|
|||||||
String,
|
String,
|
||||||
ByteArray,
|
ByteArray,
|
||||||
Optional,
|
Optional,
|
||||||
|
Unit,
|
||||||
#[cfg(any(feature = "std", feature = "alloc"))]
|
#[cfg(any(feature = "std", feature = "alloc"))]
|
||||||
UnitStruct,
|
UnitStruct,
|
||||||
Sequence,
|
Sequence,
|
||||||
@@ -69,6 +70,7 @@ impl Display for Unsupported {
|
|||||||
Unsupported::String => formatter.write_str("a string"),
|
Unsupported::String => formatter.write_str("a string"),
|
||||||
Unsupported::ByteArray => formatter.write_str("a byte array"),
|
Unsupported::ByteArray => formatter.write_str("a byte array"),
|
||||||
Unsupported::Optional => formatter.write_str("an optional"),
|
Unsupported::Optional => formatter.write_str("an optional"),
|
||||||
|
Unsupported::Unit => formatter.write_str("unit"),
|
||||||
#[cfg(any(feature = "std", feature = "alloc"))]
|
#[cfg(any(feature = "std", feature = "alloc"))]
|
||||||
Unsupported::UnitStruct => formatter.write_str("unit struct"),
|
Unsupported::UnitStruct => formatter.write_str("unit struct"),
|
||||||
Unsupported::Sequence => formatter.write_str("a sequence"),
|
Unsupported::Sequence => formatter.write_str("a sequence"),
|
||||||
@@ -182,9 +184,7 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn serialize_unit(self) -> Result<Self::Ok, Self::Error> {
|
fn serialize_unit(self) -> Result<Self::Ok, Self::Error> {
|
||||||
let mut map = try!(self.delegate.serialize_map(Some(1)));
|
Err(self.bad_type(Unsupported::Unit))
|
||||||
try!(map.serialize_entry(self.tag, self.variant_name));
|
|
||||||
map.end()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn serialize_unit_struct(self, _: &'static str) -> Result<Self::Ok, Self::Error> {
|
fn serialize_unit_struct(self, _: &'static str) -> Result<Self::Ok, Self::Error> {
|
||||||
|
|||||||
@@ -522,7 +522,7 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: ?Sized> Serialize for RefCell<T>
|
impl<T> Serialize for RefCell<T>
|
||||||
where
|
where
|
||||||
T: Serialize,
|
T: Serialize,
|
||||||
{
|
{
|
||||||
@@ -538,7 +538,7 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
impl<T: ?Sized> Serialize for Mutex<T>
|
impl<T> Serialize for Mutex<T>
|
||||||
where
|
where
|
||||||
T: Serialize,
|
T: Serialize,
|
||||||
{
|
{
|
||||||
@@ -554,7 +554,7 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
impl<T: ?Sized> Serialize for RwLock<T>
|
impl<T> Serialize for RwLock<T>
|
||||||
where
|
where
|
||||||
T: Serialize,
|
T: Serialize,
|
||||||
{
|
{
|
||||||
@@ -614,10 +614,9 @@ impl Serialize for SystemTime {
|
|||||||
S: Serializer,
|
S: Serializer,
|
||||||
{
|
{
|
||||||
use super::SerializeStruct;
|
use super::SerializeStruct;
|
||||||
let duration_since_epoch = match self.duration_since(UNIX_EPOCH) {
|
let duration_since_epoch = self
|
||||||
Ok(duration_since_epoch) => duration_since_epoch,
|
.duration_since(UNIX_EPOCH)
|
||||||
Err(_) => return Err(S::Error::custom("SystemTime must be later than UNIX_EPOCH")),
|
.map_err(|_| S::Error::custom("SystemTime must be later than UNIX_EPOCH"))?;
|
||||||
};
|
|
||||||
let mut state = try!(serializer.serialize_struct("SystemTime", 2));
|
let mut state = try!(serializer.serialize_struct("SystemTime", 2));
|
||||||
try!(state.serialize_field("secs_since_epoch", &duration_since_epoch.as_secs()));
|
try!(state.serialize_field("secs_since_epoch", &duration_since_epoch.as_secs()));
|
||||||
try!(state.serialize_field("nanos_since_epoch", &duration_since_epoch.subsec_nanos()));
|
try!(state.serialize_field("nanos_since_epoch", &duration_since_epoch.subsec_nanos()));
|
||||||
@@ -917,7 +916,7 @@ macro_rules! atomic_impl {
|
|||||||
S: Serializer,
|
S: Serializer,
|
||||||
{
|
{
|
||||||
// Matches the atomic ordering used in libcore for the Debug impl
|
// Matches the atomic ordering used in libcore for the Debug impl
|
||||||
self.load(Ordering::Relaxed).serialize(serializer)
|
self.load(Ordering::SeqCst).serialize(serializer)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)*
|
)*
|
||||||
|
|||||||
@@ -30,7 +30,7 @@
|
|||||||
//! # The Serializer trait
|
//! # The Serializer trait
|
||||||
//!
|
//!
|
||||||
//! [`Serializer`] implementations are provided by third-party crates, for
|
//! [`Serializer`] implementations are provided by third-party crates, for
|
||||||
//! example [`serde_json`], [`serde_yaml`] and [`postcard`].
|
//! example [`serde_json`], [`serde_yaml`] and [`bincode`].
|
||||||
//!
|
//!
|
||||||
//! A partial list of well-maintained formats is given on the [Serde
|
//! A partial list of well-maintained formats is given on the [Serde
|
||||||
//! website][data formats].
|
//! website][data formats].
|
||||||
@@ -99,7 +99,7 @@
|
|||||||
//! [`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
|
||||||
//! [`Serialize`]: ../trait.Serialize.html
|
//! [`Serialize`]: ../trait.Serialize.html
|
||||||
//! [`Serializer`]: ../trait.Serializer.html
|
//! [`Serializer`]: ../trait.Serializer.html
|
||||||
//! [`postcard`]: https://github.com/jamesmunns/postcard
|
//! [`bincode`]: https://github.com/bincode-org/bincode
|
||||||
//! [`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
|
||||||
//! [`serde_json`]: https://github.com/serde-rs/json
|
//! [`serde_json`]: https://github.com/serde-rs/json
|
||||||
@@ -314,7 +314,7 @@ pub trait Serialize {
|
|||||||
/// - 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 } }`.
|
||||||
///
|
///
|
||||||
/// Many Serde serializers produce text or binary data as output, for example
|
/// Many Serde serializers produce text or binary data as output, for example
|
||||||
/// JSON or Postcard. This is not a requirement of the `Serializer` trait, and
|
/// JSON or Bincode. This is not a requirement of the `Serializer` trait, and
|
||||||
/// there are serializers that do not produce text or binary output. One example
|
/// there are serializers that do not produce text or binary output. One example
|
||||||
/// is the `serde_json::value::Serializer` (distinct from the main `serde_json`
|
/// is the `serde_json::value::Serializer` (distinct from the main `serde_json`
|
||||||
/// serializer) that produces a `serde_json::Value` data structure in memory as
|
/// serializer) that produces a `serde_json::Value` data structure in memory as
|
||||||
@@ -1423,7 +1423,7 @@ pub trait Serializer: Sized {
|
|||||||
/// Some types have a human-readable form that may be somewhat expensive to
|
/// Some types have a human-readable form that may be somewhat expensive to
|
||||||
/// construct, as well as a binary form that is compact and efficient.
|
/// construct, as well as a binary form that is compact and efficient.
|
||||||
/// Generally text-based formats like JSON and YAML will prefer to use the
|
/// Generally text-based formats like JSON and YAML will prefer to use the
|
||||||
/// human-readable one and binary formats like Postcard will prefer the
|
/// human-readable one and binary formats like Bincode will prefer the
|
||||||
/// compact one.
|
/// compact one.
|
||||||
///
|
///
|
||||||
/// ```edition2018
|
/// ```edition2018
|
||||||
|
|||||||
+15
-12
@@ -1,25 +1,23 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "serde_derive"
|
name = "serde_derive"
|
||||||
version = "1.0.146" # remember to update html_root_url
|
version = "1.0.137" # 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"]
|
|
||||||
description = "Macros 1.1 implementation of #[derive(Serialize, Deserialize)]"
|
|
||||||
documentation = "https://serde.rs/derive.html"
|
|
||||||
homepage = "https://serde.rs"
|
|
||||||
include = ["build.rs", "src/**/*.rs", "crates-io.md", "README.md", "LICENSE-APACHE", "LICENSE-MIT"]
|
|
||||||
keywords = ["serde", "serialization", "no_std", "derive"]
|
|
||||||
license = "MIT OR Apache-2.0"
|
|
||||||
readme = "crates-io.md"
|
|
||||||
repository = "https://github.com/serde-rs/serde"
|
|
||||||
rust-version = "1.31"
|
rust-version = "1.31"
|
||||||
|
license = "MIT OR Apache-2.0"
|
||||||
|
description = "Macros 1.1 implementation of #[derive(Serialize, Deserialize)]"
|
||||||
|
homepage = "https://serde.rs"
|
||||||
|
repository = "https://github.com/serde-rs/serde"
|
||||||
|
documentation = "https://serde.rs/derive.html"
|
||||||
|
keywords = ["serde", "serialization", "no_std"]
|
||||||
|
readme = "crates-io.md"
|
||||||
|
include = ["build.rs", "src/**/*.rs", "crates-io.md", "README.md", "LICENSE-APACHE", "LICENSE-MIT"]
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = []
|
default = []
|
||||||
deserialize_in_place = []
|
deserialize_in_place = []
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
name = "serde_derive"
|
crate-type = ["cdylib"]
|
||||||
proc-macro = true
|
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
proc-macro2 = "1.0"
|
proc-macro2 = "1.0"
|
||||||
@@ -31,3 +29,8 @@ serde = { version = "1.0", path = "../serde" }
|
|||||||
|
|
||||||
[package.metadata.docs.rs]
|
[package.metadata.docs.rs]
|
||||||
targets = ["x86_64-unknown-linux-gnu"]
|
targets = ["x86_64-unknown-linux-gnu"]
|
||||||
|
|
||||||
|
[workspace]
|
||||||
|
|
||||||
|
[patch.crates-io]
|
||||||
|
proc-macro2 = { git = "https://github.com/dtolnay/watt" }
|
||||||
|
|||||||
@@ -13,14 +13,14 @@ fn main() {
|
|||||||
|
|
||||||
// Underscore const names stabilized in Rust 1.37:
|
// Underscore const names stabilized in Rust 1.37:
|
||||||
// https://blog.rust-lang.org/2019/08/15/Rust-1.37.0.html#using-unnamed-const-items-for-macros
|
// https://blog.rust-lang.org/2019/08/15/Rust-1.37.0.html#using-unnamed-const-items-for-macros
|
||||||
if minor < 37 {
|
if minor >= 37 {
|
||||||
println!("cargo:rustc-cfg=no_underscore_consts");
|
println!("cargo:rustc-cfg=underscore_consts");
|
||||||
}
|
}
|
||||||
|
|
||||||
// The ptr::addr_of! macro stabilized in Rust 1.51:
|
// The ptr::addr_of! macro stabilized in Rust 1.51:
|
||||||
// https://blog.rust-lang.org/2021/03/25/Rust-1.51.0.html#stabilized-apis
|
// https://blog.rust-lang.org/2021/03/25/Rust-1.51.0.html#stabilized-apis
|
||||||
if minor < 51 {
|
if minor >= 51 {
|
||||||
println!("cargo:rustc-cfg=no_ptr_addr_of");
|
println!("cargo:rustc-cfg=ptr_addr_of");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,10 +12,10 @@ pub fn wrap_in_const(
|
|||||||
) -> TokenStream {
|
) -> TokenStream {
|
||||||
let try_replacement = try::replacement();
|
let try_replacement = try::replacement();
|
||||||
|
|
||||||
let dummy_const = if cfg!(no_underscore_consts) {
|
let dummy_const = if cfg!(underscore_consts) {
|
||||||
format_ident!("_IMPL_{}_FOR_{}", trait_, unraw(ty))
|
|
||||||
} else {
|
|
||||||
format_ident!("_")
|
format_ident!("_")
|
||||||
|
} else {
|
||||||
|
format_ident!("_IMPL_{}_FOR_{}", trait_, unraw(ty))
|
||||||
};
|
};
|
||||||
|
|
||||||
let use_serde = match serde_path {
|
let use_serde = match serde_path {
|
||||||
|
|||||||
+19
-16
@@ -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.146")]
|
#![doc(html_root_url = "https://docs.rs/serde_derive/1.0.137")]
|
||||||
#![allow(unknown_lints, bare_trait_objects)]
|
#![allow(unknown_lints, bare_trait_objects)]
|
||||||
// Ignored clippy lints
|
// Ignored clippy lints
|
||||||
#![allow(
|
#![allow(
|
||||||
@@ -68,12 +68,11 @@ extern crate quote;
|
|||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate syn;
|
extern crate syn;
|
||||||
|
|
||||||
extern crate proc_macro;
|
|
||||||
extern crate proc_macro2;
|
extern crate proc_macro2;
|
||||||
|
|
||||||
mod internals;
|
mod internals;
|
||||||
|
|
||||||
use proc_macro::TokenStream;
|
use proc_macro2::TokenStream;
|
||||||
use syn::DeriveInput;
|
use syn::DeriveInput;
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
@@ -87,23 +86,27 @@ mod pretend;
|
|||||||
mod ser;
|
mod ser;
|
||||||
mod try;
|
mod try;
|
||||||
|
|
||||||
#[proc_macro_derive(Serialize, attributes(serde))]
|
#[no_mangle]
|
||||||
pub fn derive_serialize(input: TokenStream) -> TokenStream {
|
pub extern "C" fn derive_serialize(input: TokenStream) -> TokenStream {
|
||||||
let mut input = parse_macro_input!(input as DeriveInput);
|
let mut input: DeriveInput = match syn::parse2(input) {
|
||||||
ser::expand_derive_serialize(&mut input)
|
Ok(input) => input,
|
||||||
.unwrap_or_else(to_compile_errors)
|
Err(err) => return err.to_compile_error(),
|
||||||
.into()
|
};
|
||||||
|
|
||||||
|
ser::expand_derive_serialize(&mut input).unwrap_or_else(to_compile_errors)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[proc_macro_derive(Deserialize, attributes(serde))]
|
#[no_mangle]
|
||||||
pub fn derive_deserialize(input: TokenStream) -> TokenStream {
|
pub extern "C" fn derive_deserialize(input: TokenStream) -> TokenStream {
|
||||||
let mut input = parse_macro_input!(input as DeriveInput);
|
let mut input: DeriveInput = match syn::parse2(input) {
|
||||||
de::expand_derive_deserialize(&mut input)
|
Ok(input) => input,
|
||||||
.unwrap_or_else(to_compile_errors)
|
Err(err) => return err.to_compile_error(),
|
||||||
.into()
|
};
|
||||||
|
|
||||||
|
de::expand_derive_deserialize(&mut input).unwrap_or_else(to_compile_errors)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn to_compile_errors(errors: Vec<syn::Error>) -> proc_macro2::TokenStream {
|
fn to_compile_errors(errors: Vec<syn::Error>) -> TokenStream {
|
||||||
let compile_errors = errors.iter().map(syn::Error::to_compile_error);
|
let compile_errors = errors.iter().map(syn::Error::to_compile_error);
|
||||||
quote!(#(#compile_errors)*)
|
quote!(#(#compile_errors)*)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -97,7 +97,7 @@ fn pretend_fields_used_struct_packed(cont: &Container, fields: &[Field]) -> Toke
|
|||||||
|
|
||||||
let members = fields.iter().map(|field| &field.member).collect::<Vec<_>>();
|
let members = fields.iter().map(|field| &field.member).collect::<Vec<_>>();
|
||||||
|
|
||||||
#[cfg(not(no_ptr_addr_of))]
|
#[cfg(ptr_addr_of)]
|
||||||
{
|
{
|
||||||
quote! {
|
quote! {
|
||||||
match _serde::__private::None::<&#type_ident #ty_generics> {
|
match _serde::__private::None::<&#type_ident #ty_generics> {
|
||||||
@@ -111,7 +111,7 @@ fn pretend_fields_used_struct_packed(cont: &Container, fields: &[Field]) -> Toke
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(no_ptr_addr_of)]
|
#[cfg(not(ptr_addr_of))]
|
||||||
{
|
{
|
||||||
let placeholders = (0usize..).map(|i| format_ident!("__v{}", i));
|
let placeholders = (0usize..).map(|i| format_ident!("__v{}", i));
|
||||||
|
|
||||||
|
|||||||
@@ -2,14 +2,14 @@
|
|||||||
name = "serde_derive_internals"
|
name = "serde_derive_internals"
|
||||||
version = "0.26.0" # remember to update html_root_url
|
version = "0.26.0" # 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>"]
|
||||||
description = "AST representation used by Serde derive macros. Unstable."
|
|
||||||
documentation = "https://docs.rs/serde_derive_internals"
|
|
||||||
homepage = "https://serde.rs"
|
|
||||||
include = ["lib.rs", "src/**/*.rs", "LICENSE-APACHE", "LICENSE-MIT"]
|
|
||||||
keywords = ["serde", "serialization"]
|
|
||||||
license = "MIT OR Apache-2.0"
|
|
||||||
repository = "https://github.com/serde-rs/serde"
|
|
||||||
rust-version = "1.31"
|
rust-version = "1.31"
|
||||||
|
license = "MIT OR Apache-2.0"
|
||||||
|
description = "AST representation used by Serde derive macros. Unstable."
|
||||||
|
homepage = "https://serde.rs"
|
||||||
|
repository = "https://github.com/serde-rs/serde"
|
||||||
|
documentation = "https://docs.rs/serde_derive_internals"
|
||||||
|
keywords = ["serde", "serialization"]
|
||||||
|
include = ["lib.rs", "src/**/*.rs", "LICENSE-APACHE", "LICENSE-MIT"]
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
path = "lib.rs"
|
path = "lib.rs"
|
||||||
|
|||||||
+10
-11
@@ -1,18 +1,17 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "serde_test"
|
name = "serde_test"
|
||||||
version = "1.0.146" # remember to update html_root_url
|
version = "1.0.137" # 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"
|
|
||||||
categories = ["development-tools::testing"]
|
|
||||||
description = "Token De/Serializer for testing De/Serialize implementations"
|
|
||||||
documentation = "https://docs.serde.rs/serde_test/"
|
|
||||||
homepage = "https://serde.rs"
|
|
||||||
include = ["build.rs", "src/**/*.rs", "crates-io.md", "README.md", "LICENSE-APACHE", "LICENSE-MIT"]
|
|
||||||
keywords = ["serde", "serialization", "testing", "dev-dependencies"]
|
|
||||||
license = "MIT OR Apache-2.0"
|
|
||||||
readme = "crates-io.md"
|
|
||||||
repository = "https://github.com/serde-rs/serde"
|
|
||||||
rust-version = "1.13"
|
rust-version = "1.13"
|
||||||
|
license = "MIT OR Apache-2.0"
|
||||||
|
description = "Token De/Serializer for testing De/Serialize implementations"
|
||||||
|
homepage = "https://serde.rs"
|
||||||
|
repository = "https://github.com/serde-rs/serde"
|
||||||
|
documentation = "https://docs.serde.rs/serde_test/"
|
||||||
|
keywords = ["serde", "serialization"]
|
||||||
|
readme = "crates-io.md"
|
||||||
|
include = ["build.rs", "src/**/*.rs", "crates-io.md", "README.md", "LICENSE-APACHE", "LICENSE-MIT"]
|
||||||
|
build = "build.rs"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
serde = { version = "1.0.60", path = "../serde" }
|
serde = { version = "1.0.60", path = "../serde" }
|
||||||
|
|||||||
+2
-2
@@ -13,8 +13,8 @@ fn main() {
|
|||||||
|
|
||||||
// #[track_caller] stabilized in Rust 1.46:
|
// #[track_caller] stabilized in Rust 1.46:
|
||||||
// https://blog.rust-lang.org/2020/08/27/Rust-1.46.0.html#track_caller
|
// https://blog.rust-lang.org/2020/08/27/Rust-1.46.0.html#track_caller
|
||||||
if minor < 46 {
|
if minor >= 46 {
|
||||||
println!("cargo:rustc-cfg=no_track_caller");
|
println!("cargo:rustc-cfg=track_caller");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ use std::fmt::Debug;
|
|||||||
/// Token::StructEnd,
|
/// Token::StructEnd,
|
||||||
/// ]);
|
/// ]);
|
||||||
/// ```
|
/// ```
|
||||||
#[cfg_attr(not(no_track_caller), track_caller)]
|
#[cfg_attr(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])
|
||||||
where
|
where
|
||||||
T: Serialize + Deserialize<'de> + PartialEq + Debug,
|
T: Serialize + Deserialize<'de> + PartialEq + Debug,
|
||||||
@@ -59,7 +59,7 @@ where
|
|||||||
/// Token::StructEnd,
|
/// Token::StructEnd,
|
||||||
/// ]);
|
/// ]);
|
||||||
/// ```
|
/// ```
|
||||||
#[cfg_attr(not(no_track_caller), track_caller)]
|
#[cfg_attr(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])
|
||||||
where
|
where
|
||||||
T: Serialize,
|
T: Serialize,
|
||||||
@@ -112,7 +112,7 @@ where
|
|||||||
/// assert_ser_tokens_error(&example, expected, error);
|
/// assert_ser_tokens_error(&example, expected, error);
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
#[cfg_attr(not(no_track_caller), track_caller)]
|
#[cfg_attr(track_caller, track_caller)]
|
||||||
pub fn assert_ser_tokens_error<T: ?Sized>(value: &T, tokens: &[Token], error: &str)
|
pub fn assert_ser_tokens_error<T: ?Sized>(value: &T, tokens: &[Token], error: &str)
|
||||||
where
|
where
|
||||||
T: Serialize,
|
T: Serialize,
|
||||||
@@ -150,7 +150,7 @@ where
|
|||||||
/// Token::StructEnd,
|
/// Token::StructEnd,
|
||||||
/// ]);
|
/// ]);
|
||||||
/// ```
|
/// ```
|
||||||
#[cfg_attr(not(no_track_caller), track_caller)]
|
#[cfg_attr(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])
|
||||||
where
|
where
|
||||||
T: Deserialize<'de> + PartialEq + Debug,
|
T: Deserialize<'de> + PartialEq + Debug,
|
||||||
@@ -203,7 +203,7 @@ where
|
|||||||
/// "unknown field `x`, expected `a` or `b`",
|
/// "unknown field `x`, expected `a` or `b`",
|
||||||
/// );
|
/// );
|
||||||
/// ```
|
/// ```
|
||||||
#[cfg_attr(not(no_track_caller), track_caller)]
|
#[cfg_attr(track_caller, track_caller)]
|
||||||
pub fn assert_de_tokens_error<'de, T>(tokens: &'de [Token], error: &str)
|
pub fn assert_de_tokens_error<'de, T>(tokens: &'de [Token], error: &str)
|
||||||
where
|
where
|
||||||
T: Deserialize<'de>,
|
T: Deserialize<'de>,
|
||||||
|
|||||||
@@ -144,7 +144,7 @@
|
|||||||
//! # }
|
//! # }
|
||||||
//! ```
|
//! ```
|
||||||
|
|
||||||
#![doc(html_root_url = "https://docs.rs/serde_test/1.0.146")]
|
#![doc(html_root_url = "https://docs.rs/serde_test/1.0.137")]
|
||||||
#![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))]
|
||||||
|
|||||||
@@ -2,9 +2,9 @@
|
|||||||
name = "serde_test_suite"
|
name = "serde_test_suite"
|
||||||
version = "0.0.0"
|
version = "0.0.0"
|
||||||
authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>", "David Tolnay <dtolnay@gmail.com>"]
|
authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>", "David Tolnay <dtolnay@gmail.com>"]
|
||||||
build = "build.rs"
|
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
publish = false
|
publish = false
|
||||||
|
build = "build.rs"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
expandtest = []
|
expandtest = []
|
||||||
@@ -21,7 +21,9 @@ fnv = "1.0"
|
|||||||
macrotest = "=1.0.9"
|
macrotest = "=1.0.9"
|
||||||
prettyplease = "=0.1.14"
|
prettyplease = "=0.1.14"
|
||||||
rustversion = "1.0"
|
rustversion = "1.0"
|
||||||
serde = { path = "../serde", features = ["rc", "derive"] }
|
serde = { path = "../serde", features = ["rc"] }
|
||||||
serde_derive = { path = "../serde_derive", features = ["deserialize_in_place"] }
|
wa-serde-derive = { path = "../wa-serde-derive" }
|
||||||
serde_test = { path = "../serde_test" }
|
serde_test = { path = "../serde_test" }
|
||||||
trybuild = { version = "1.0.66", features = ["diff"] }
|
trybuild = { version = "1.0.49", features = ["diff"] }
|
||||||
|
|
||||||
|
[workspace]
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "serde_derive_tests_no_std"
|
name = "serde_derive_tests_no_std"
|
||||||
version = "0.0.0"
|
version = "0.0.0"
|
||||||
authors = ["David Tolnay <dtolnay@gmail.com>"]
|
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
publish = false
|
publish = false
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
#![cfg(any())]
|
||||||
|
|
||||||
#[cfg_attr(target_os = "emscripten", ignore)]
|
#[cfg_attr(target_os = "emscripten", ignore)]
|
||||||
#[rustversion::attr(not(nightly), ignore)]
|
#[rustversion::attr(not(nightly), ignore)]
|
||||||
#[cfg_attr(miri, ignore)]
|
#[cfg_attr(miri, ignore)]
|
||||||
|
|||||||
@@ -11,6 +11,7 @@
|
|||||||
|
|
||||||
use serde::de::{self, MapAccess, Unexpected, Visitor};
|
use serde::de::{self, MapAccess, Unexpected, Visitor};
|
||||||
use serde::{Deserialize, Deserializer, Serialize, Serializer};
|
use serde::{Deserialize, Deserializer, Serialize, Serializer};
|
||||||
|
use serde_derive::{Deserialize, Serialize};
|
||||||
|
|
||||||
use std::collections::{BTreeMap, HashMap};
|
use std::collections::{BTreeMap, HashMap};
|
||||||
use std::convert::TryFrom;
|
use std::convert::TryFrom;
|
||||||
@@ -1235,7 +1236,7 @@ fn serialize_variant_as_string<S>(f1: &str, f2: &u8, serializer: S) -> Result<S:
|
|||||||
where
|
where
|
||||||
S: Serializer,
|
S: Serializer,
|
||||||
{
|
{
|
||||||
serializer.serialize_str(format!("{f1};{f2:?}").as_str())
|
serializer.serialize_str(format!("{};{:?}", f1, f2).as_str())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn deserialize_string_as_variant<'de, D>(deserializer: D) -> Result<(String, u8), D::Error>
|
fn deserialize_string_as_variant<'de, D>(deserializer: D) -> Result<(String, u8), D::Error>
|
||||||
@@ -2302,25 +2303,6 @@ fn test_internally_tagged_enum_containing_flatten() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_internally_tagged_enum_new_type_with_unit() {
|
|
||||||
#[derive(Serialize, Deserialize, PartialEq, Debug)]
|
|
||||||
#[serde(tag = "t")]
|
|
||||||
enum Data {
|
|
||||||
A(()),
|
|
||||||
}
|
|
||||||
|
|
||||||
assert_tokens(
|
|
||||||
&Data::A(()),
|
|
||||||
&[
|
|
||||||
Token::Map { len: Some(1) },
|
|
||||||
Token::Str("t"),
|
|
||||||
Token::Str("A"),
|
|
||||||
Token::MapEnd,
|
|
||||||
],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_adjacently_tagged_enum_containing_flatten() {
|
fn test_adjacently_tagged_enum_containing_flatten() {
|
||||||
#[derive(Serialize, Deserialize, PartialEq, Debug)]
|
#[derive(Serialize, Deserialize, PartialEq, Debug)]
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
)]
|
)]
|
||||||
|
|
||||||
use serde::{Deserialize, Deserializer};
|
use serde::{Deserialize, Deserializer};
|
||||||
|
use serde_derive::Deserialize;
|
||||||
use serde_test::{assert_de_tokens, assert_de_tokens_error, Token};
|
use serde_test::{assert_de_tokens, assert_de_tokens_error, Token};
|
||||||
|
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
|
|||||||
@@ -5,7 +5,6 @@
|
|||||||
clippy::empty_enum,
|
clippy::empty_enum,
|
||||||
clippy::manual_assert,
|
clippy::manual_assert,
|
||||||
clippy::needless_pass_by_value,
|
clippy::needless_pass_by_value,
|
||||||
clippy::uninlined_format_args,
|
|
||||||
clippy::unreadable_literal
|
clippy::unreadable_literal
|
||||||
)]
|
)]
|
||||||
#![cfg_attr(feature = "unstable", feature(never_type))]
|
#![cfg_attr(feature = "unstable", feature(never_type))]
|
||||||
@@ -35,6 +34,7 @@ use std::sync::atomic::{AtomicI64, AtomicU64};
|
|||||||
use fnv::FnvHasher;
|
use fnv::FnvHasher;
|
||||||
use serde::de::DeserializeOwned;
|
use serde::de::DeserializeOwned;
|
||||||
use serde::{Deserialize, Deserializer};
|
use serde::{Deserialize, Deserializer};
|
||||||
|
use serde_derive::Deserialize;
|
||||||
use serde_test::{assert_de_tokens, Configure, Token};
|
use serde_test::{assert_de_tokens, Configure, Token};
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
|
|
||||||
use serde::de::IntoDeserializer;
|
use serde::de::IntoDeserializer;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
use serde_derive::Deserialize;
|
||||||
use serde_test::{assert_de_tokens_error, Token};
|
use serde_test::{assert_de_tokens_error, Token};
|
||||||
use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet};
|
use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet};
|
||||||
use std::ffi::{CStr, CString};
|
use std::ffi::{CStr, CString};
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
// 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.
|
||||||
|
|
||||||
|
#![cfg(any())]
|
||||||
#![deny(warnings)]
|
#![deny(warnings)]
|
||||||
#![allow(
|
#![allow(
|
||||||
unknown_lints,
|
unknown_lints,
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
#![allow(clippy::derive_partial_eq_without_eq)]
|
#![allow(clippy::derive_partial_eq_without_eq)]
|
||||||
|
|
||||||
use serde::Deserialize;
|
use serde_derive::Deserialize;
|
||||||
use serde_test::{assert_de_tokens, Token};
|
use serde_test::{assert_de_tokens, Token};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ use serde::de::{
|
|||||||
DeserializeSeed, EnumAccess, IgnoredAny, IntoDeserializer, VariantAccess, Visitor,
|
DeserializeSeed, EnumAccess, IgnoredAny, IntoDeserializer, VariantAccess, Visitor,
|
||||||
};
|
};
|
||||||
use serde::{forward_to_deserialize_any, Deserialize, Deserializer};
|
use serde::{forward_to_deserialize_any, Deserialize, Deserializer};
|
||||||
|
use serde_derive::Deserialize;
|
||||||
|
|
||||||
#[derive(PartialEq, Debug, Deserialize)]
|
#[derive(PartialEq, Debug, Deserialize)]
|
||||||
enum Target {
|
enum Target {
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
mod bytes;
|
mod bytes;
|
||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde_derive::{Deserialize, Serialize};
|
||||||
use serde_test::{
|
use serde_test::{
|
||||||
assert_de_tokens, assert_de_tokens_error, assert_ser_tokens, assert_tokens, Token,
|
assert_de_tokens, assert_de_tokens_error, assert_ser_tokens, assert_tokens, Token,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#![allow(clippy::redundant_field_names)]
|
#![allow(clippy::redundant_field_names)]
|
||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde_derive::{Deserialize, Serialize};
|
||||||
|
|
||||||
mod remote {
|
mod remote {
|
||||||
pub struct Unit;
|
pub struct Unit;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#![allow(clippy::used_underscore_binding)]
|
#![allow(clippy::used_underscore_binding)]
|
||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde_derive::{Deserialize, Serialize};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_self() {
|
fn test_self() {
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ use std::sync::atomic::{
|
|||||||
AtomicBool, AtomicI16, AtomicI32, AtomicI8, AtomicIsize, AtomicU16, AtomicU32, AtomicU8,
|
AtomicBool, AtomicI16, AtomicI32, AtomicI8, AtomicIsize, AtomicU16, AtomicU32, AtomicU8,
|
||||||
AtomicUsize,
|
AtomicUsize,
|
||||||
};
|
};
|
||||||
use std::sync::{Arc, Mutex, RwLock, Weak as ArcWeak};
|
use std::sync::{Arc, Weak as ArcWeak};
|
||||||
use std::time::{Duration, UNIX_EPOCH};
|
use std::time::{Duration, UNIX_EPOCH};
|
||||||
|
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
@@ -22,7 +22,7 @@ use std::str;
|
|||||||
use std::sync::atomic::{AtomicI64, AtomicU64};
|
use std::sync::atomic::{AtomicI64, AtomicU64};
|
||||||
|
|
||||||
use fnv::FnvHasher;
|
use fnv::FnvHasher;
|
||||||
use serde::Serialize;
|
use serde_derive::Serialize;
|
||||||
use serde_test::{assert_ser_tokens, assert_ser_tokens_error, Configure, Token};
|
use serde_test::{assert_ser_tokens, assert_ser_tokens_error, Configure, Token};
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
@@ -800,14 +800,17 @@ fn test_never_result() {
|
|||||||
#[test]
|
#[test]
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
fn test_cannot_serialize_paths() {
|
fn test_cannot_serialize_paths() {
|
||||||
use std::ffi::OsStr;
|
let path = unsafe { str::from_utf8_unchecked(b"Hello \xF0\x90\x80World") };
|
||||||
use std::os::unix::ffi::OsStrExt;
|
|
||||||
|
|
||||||
assert_ser_tokens_error(
|
assert_ser_tokens_error(
|
||||||
&Path::new(OsStr::from_bytes(b"Hello \xF0\x90\x80World")),
|
&Path::new(path),
|
||||||
&[],
|
&[],
|
||||||
"path contains invalid UTF-8 characters",
|
"path contains invalid UTF-8 characters",
|
||||||
);
|
);
|
||||||
|
|
||||||
|
let mut path_buf = PathBuf::new();
|
||||||
|
path_buf.push(path);
|
||||||
|
|
||||||
|
assert_ser_tokens_error(&path_buf, &[], "path contains invalid UTF-8 characters");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -847,39 +850,3 @@ fn test_integer128() {
|
|||||||
|
|
||||||
assert_ser_tokens_error(&1u128, &[], "u128 is not supported");
|
assert_ser_tokens_error(&1u128, &[], "u128 is not supported");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_refcell_dst() {
|
|
||||||
assert_ser_tokens(
|
|
||||||
&RefCell::new([true]) as &RefCell<[bool]>,
|
|
||||||
&[
|
|
||||||
Token::Seq { len: Some(1) },
|
|
||||||
Token::Bool(true),
|
|
||||||
Token::SeqEnd,
|
|
||||||
],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_mutex_dst() {
|
|
||||||
assert_ser_tokens(
|
|
||||||
&Mutex::new([true]) as &Mutex<[bool]>,
|
|
||||||
&[
|
|
||||||
Token::Seq { len: Some(1) },
|
|
||||||
Token::Bool(true),
|
|
||||||
Token::SeqEnd,
|
|
||||||
],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_rwlock_dst() {
|
|
||||||
assert_ser_tokens(
|
|
||||||
&RwLock::new([true]) as &RwLock<[bool]>,
|
|
||||||
&[
|
|
||||||
Token::Seq { len: Some(1) },
|
|
||||||
Token::Bool(true),
|
|
||||||
Token::SeqEnd,
|
|
||||||
],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_gen_custom_serde() {
|
fn test_gen_custom_serde() {
|
||||||
#[derive(serde::Serialize, serde::Deserialize)]
|
#[derive(serde_derive::Serialize, serde_derive::Deserialize)]
|
||||||
#[serde(crate = "fake_serde")]
|
#[serde(crate = "fake_serde")]
|
||||||
struct Foo;
|
struct Foo;
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
use serde::de::value::{self, MapAccessDeserializer};
|
use serde::de::value::{self, MapAccessDeserializer};
|
||||||
use serde::de::{IntoDeserializer, MapAccess, Visitor};
|
use serde::de::{IntoDeserializer, MapAccess, Visitor};
|
||||||
use serde::{Deserialize, Deserializer};
|
use serde::{Deserialize, Deserializer};
|
||||||
|
use serde_derive::Deserialize;
|
||||||
use serde_test::{assert_de_tokens, Token};
|
use serde_test::{assert_de_tokens, Token};
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
|
||||||
|
|||||||
@@ -1,17 +1,17 @@
|
|||||||
error[E0308]: mismatched types
|
error[E0308]: mismatched types
|
||||||
--> tests/ui/remote/wrong_ser.rs:9:10
|
--> tests/ui/remote/wrong_ser.rs:9:10
|
||||||
|
|
|
|
||||||
9 | #[derive(Serialize)]
|
9 | #[derive(Serialize)]
|
||||||
| ^^^^^^^^^
|
| ^^^^^^^^^
|
||||||
| |
|
| |
|
||||||
| expected `u8`, found `u16`
|
| expected `u8`, found `u16`
|
||||||
| arguments to this function are incorrect
|
| arguments to this function are incorrect
|
||||||
|
|
|
|
||||||
= note: expected reference `&u8`
|
= note: expected reference `&u8`
|
||||||
found reference `&u16`
|
found reference `&u16`
|
||||||
note: function defined here
|
note: function defined here
|
||||||
--> $WORKSPACE/serde/src/private/ser.rs
|
--> $WORKSPACE/serde/src/private/ser.rs
|
||||||
|
|
|
|
||||||
| pub fn constrain<T: ?Sized>(t: &T) -> &T {
|
| pub fn constrain<T: ?Sized>(t: &T) -> &T {
|
||||||
| ^^^^^^^^^
|
| ^^^^^^^^^
|
||||||
= note: this error originates in the derive macro `Serialize` (in Nightly builds, run with -Z macro-backtrace for more info)
|
= note: this error originates in the derive macro `Serialize` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
*.wasm
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
[package]
|
||||||
|
name = "wa-serde-derive"
|
||||||
|
version = "0.1.137"
|
||||||
|
authors = ["David Tolnay <dtolnay@gmail.com>"]
|
||||||
|
license = "MIT OR Apache-2.0"
|
||||||
|
description = "serde_derive compiled to wasm"
|
||||||
|
repository = "https://github.com/dtolnay/watt"
|
||||||
|
include = ["src"]
|
||||||
|
|
||||||
|
[lib]
|
||||||
|
name = "serde_derive"
|
||||||
|
proc-macro = true
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
watt = "0.4"
|
||||||
|
|
||||||
|
[workspace]
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
extern crate proc_macro;
|
||||||
|
extern crate watt;
|
||||||
|
|
||||||
|
use proc_macro::TokenStream;
|
||||||
|
use watt::WasmMacro;
|
||||||
|
|
||||||
|
static MACRO: WasmMacro = WasmMacro::new(WASM);
|
||||||
|
static WASM: &[u8] = include_bytes!("serde_derive.wasm");
|
||||||
|
|
||||||
|
#[proc_macro_derive(Serialize, attributes(serde))]
|
||||||
|
pub fn derive_serialize(input: TokenStream) -> TokenStream {
|
||||||
|
MACRO.proc_macro_derive("derive_serialize", input)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[proc_macro_derive(Deserialize, attributes(serde))]
|
||||||
|
pub fn derive_deserialize(input: TokenStream) -> TokenStream {
|
||||||
|
MACRO.proc_macro_derive("derive_deserialize", input)
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user