mirror of
https://github.com/pezkuwichain/serde.git
synced 2026-04-27 15:47:57 +00:00
Compare commits
40 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| b6a77c4413 | |||
| 33438850a6 | |||
| c083cfd65e | |||
| 4cea81f93f | |||
| 2d36be753a | |||
| 738d29eaa9 | |||
| b536fb67a4 | |||
| b10c23a950 | |||
| 85a5cf7cb1 | |||
| 192f5cd647 | |||
| 7dceee64fe | |||
| 8ad6ae71c6 | |||
| 3ea85a28cf | |||
| 273ecdb786 | |||
| de40eb7306 | |||
| b9c44073ce | |||
| d6e5947ad2 | |||
| 668651ee01 | |||
| fb1cacc10e | |||
| 735e56c26f | |||
| 97de3dccbb | |||
| 690467cbe2 | |||
| 71efd8ffda | |||
| 9bb196ae6e | |||
| ce75418e40 | |||
| 78c7f09e28 | |||
| e7269ac84e | |||
| 34866e20a8 | |||
| 3ae2bee272 | |||
| d0fb958e99 | |||
| b941c63a53 | |||
| cf70c3fb05 | |||
| f249e72162 | |||
| 92e0b62c6b | |||
| cf32a5b204 | |||
| 7b0e06c825 | |||
| 3158bf9093 | |||
| 01fade764c | |||
| 210c2419be | |||
| 4c29eea790 |
+13
-5
@@ -39,15 +39,23 @@ matrix:
|
|||||||
- cd "${TRAVIS_BUILD_DIR}/serde_test"
|
- cd "${TRAVIS_BUILD_DIR}/serde_test"
|
||||||
- cargo build
|
- cargo build
|
||||||
|
|
||||||
- rust: 1.15.0
|
- rust: 1.19.0
|
||||||
script:
|
|
||||||
- cd "${TRAVIS_BUILD_DIR}/serde_derive"
|
|
||||||
- cargo build
|
|
||||||
|
|
||||||
- rust: 1.20.0
|
- rust: 1.20.0
|
||||||
- rust: 1.21.0
|
- rust: 1.21.0
|
||||||
- rust: 1.25.0
|
- rust: 1.25.0
|
||||||
- rust: 1.26.0
|
- rust: 1.26.0
|
||||||
|
|
||||||
|
# Work around failing to parse manifest because editions are unstable.
|
||||||
|
- rust: 1.27.0
|
||||||
|
before_script: sed -i /test_suite/d Cargo.toml
|
||||||
|
- rust: 1.28.0
|
||||||
|
before_script: sed -i /test_suite/d Cargo.toml
|
||||||
|
|
||||||
|
- rust: 1.31.0
|
||||||
|
script:
|
||||||
|
- cd "${TRAVIS_BUILD_DIR}/serde_derive"
|
||||||
|
- cargo build
|
||||||
|
|
||||||
- rust: 1.34.0
|
- rust: 1.34.0
|
||||||
|
|
||||||
- rust: 1.36.0
|
- rust: 1.36.0
|
||||||
|
|||||||
@@ -1,11 +1,13 @@
|
|||||||
# Serde   [![Build Status]][travis] [![Latest Version]][crates.io] [![Rustc Version 1.13+]][rustc]
|
# Serde   [![Build Status]][travis] [![Latest Version]][crates.io] [![serde: rustc 1.13+]][Rust 1.13] [![serde_derive: rustc 1.31+]][Rust 1.31]
|
||||||
|
|
||||||
[Build Status]: https://api.travis-ci.org/serde-rs/serde.svg?branch=master
|
[Build Status]: https://api.travis-ci.org/serde-rs/serde.svg?branch=master
|
||||||
[travis]: https://travis-ci.org/serde-rs/serde
|
[travis]: https://travis-ci.org/serde-rs/serde
|
||||||
[Latest Version]: https://img.shields.io/crates/v/serde.svg
|
[Latest Version]: https://img.shields.io/crates/v/serde.svg
|
||||||
[crates.io]: https://crates.io/crates/serde
|
[crates.io]: https://crates.io/crates/serde
|
||||||
[Rustc Version 1.13+]: https://img.shields.io/badge/rustc-1.13+-lightgray.svg
|
[serde: rustc 1.13+]: https://img.shields.io/badge/serde-rustc_1.13+-lightgray.svg
|
||||||
[rustc]: https://blog.rust-lang.org/2016/11/10/Rust-1.13.html
|
[serde_derive: rustc 1.31+]: https://img.shields.io/badge/serde_derive-rustc_1.31+-lightgray.svg
|
||||||
|
[Rust 1.13]: https://blog.rust-lang.org/2016/11/10/Rust-1.13.html
|
||||||
|
[Rust 1.31]: https://blog.rust-lang.org/2018/12/06/Rust-1.31-and-rust-2018.html
|
||||||
|
|
||||||
**Serde is a framework for *ser*ializing and *de*serializing Rust data structures efficiently and generically.**
|
**Serde is a framework for *ser*ializing and *de*serializing Rust data structures efficiently and generically.**
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "serde"
|
name = "serde"
|
||||||
version = "1.0.95" # remember to update html_root_url
|
version = "1.0.100" # 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 OR Apache-2.0"
|
license = "MIT OR Apache-2.0"
|
||||||
description = "A generic serialization/deserialization framework"
|
description = "A generic serialization/deserialization framework"
|
||||||
|
|||||||
+22
-1
@@ -69,8 +69,29 @@ fn main() {
|
|||||||
println!("cargo:rustc-cfg=num_nonzero");
|
println!("cargo:rustc-cfg=num_nonzero");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TryFrom, Atomic types, and non-zero signed integers stabilized in Rust 1.34:
|
||||||
|
// https://blog.rust-lang.org/2019/04/11/Rust-1.34.0.html#tryfrom-and-tryinto
|
||||||
|
// https://blog.rust-lang.org/2019/04/11/Rust-1.34.0.html#library-stabilizations
|
||||||
if minor >= 34 {
|
if minor >= 34 {
|
||||||
println!("cargo:rustc-cfg=std_integer_atomics");
|
println!("cargo:rustc-cfg=core_try_from");
|
||||||
|
println!("cargo:rustc-cfg=num_nonzero_signed");
|
||||||
|
|
||||||
|
// Whitelist of archs that support std::sync::atomic module. Ideally we
|
||||||
|
// would use #[cfg(target_has_atomic = "...")] but it is not stable yet.
|
||||||
|
// Instead this is based on rustc's src/librustc_target/spec/*.rs.
|
||||||
|
let has_atomic64 = target.starts_with("x86_64")
|
||||||
|
|| target.starts_with("i686")
|
||||||
|
|| target.starts_with("aarch64")
|
||||||
|
|| target.starts_with("powerpc64")
|
||||||
|
|| target.starts_with("sparc64")
|
||||||
|
|| target.starts_with("mips64el");
|
||||||
|
let has_atomic32 = has_atomic64 || emscripten;
|
||||||
|
if has_atomic64 {
|
||||||
|
println!("cargo:rustc-cfg=std_atomic64");
|
||||||
|
}
|
||||||
|
if has_atomic32 {
|
||||||
|
println!("cargo:rustc-cfg=std_atomic");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+17
-4
@@ -2404,7 +2404,6 @@ macro_rules! nonzero_integers {
|
|||||||
}
|
}
|
||||||
|
|
||||||
nonzero_integers! {
|
nonzero_integers! {
|
||||||
// Not including signed NonZeroI* since they might be removed
|
|
||||||
NonZeroU8,
|
NonZeroU8,
|
||||||
NonZeroU16,
|
NonZeroU16,
|
||||||
NonZeroU32,
|
NonZeroU32,
|
||||||
@@ -2412,12 +2411,26 @@ nonzero_integers! {
|
|||||||
NonZeroUsize,
|
NonZeroUsize,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(num_nonzero_signed)]
|
||||||
|
nonzero_integers! {
|
||||||
|
NonZeroI8,
|
||||||
|
NonZeroI16,
|
||||||
|
NonZeroI32,
|
||||||
|
NonZeroI64,
|
||||||
|
NonZeroIsize,
|
||||||
|
}
|
||||||
|
|
||||||
// Currently 128-bit integers do not work on Emscripten targets so we need an
|
// Currently 128-bit integers do not work on Emscripten targets so we need an
|
||||||
// additional `#[cfg]`
|
// additional `#[cfg]`
|
||||||
serde_if_integer128! {
|
serde_if_integer128! {
|
||||||
nonzero_integers! {
|
nonzero_integers! {
|
||||||
NonZeroU128,
|
NonZeroU128,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(num_nonzero_signed)]
|
||||||
|
nonzero_integers! {
|
||||||
|
NonZeroI128,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
@@ -2546,7 +2559,7 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(all(feature = "std", std_integer_atomics))]
|
#[cfg(all(feature = "std", std_atomic))]
|
||||||
macro_rules! atomic_impl {
|
macro_rules! atomic_impl {
|
||||||
($($ty:ident)*) => {
|
($($ty:ident)*) => {
|
||||||
$(
|
$(
|
||||||
@@ -2562,14 +2575,14 @@ macro_rules! atomic_impl {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(all(feature = "std", std_integer_atomics))]
|
#[cfg(all(feature = "std", std_atomic))]
|
||||||
atomic_impl! {
|
atomic_impl! {
|
||||||
AtomicBool
|
AtomicBool
|
||||||
AtomicI8 AtomicI16 AtomicI32 AtomicIsize
|
AtomicI8 AtomicI16 AtomicI32 AtomicIsize
|
||||||
AtomicU8 AtomicU16 AtomicU32 AtomicUsize
|
AtomicU8 AtomicU16 AtomicU32 AtomicUsize
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(all(feature = "std", std_integer_atomics, not(target_os = "emscripten")))]
|
#[cfg(all(feature = "std", std_atomic64))]
|
||||||
atomic_impl! {
|
atomic_impl! {
|
||||||
AtomicI64 AtomicU64
|
AtomicI64 AtomicU64
|
||||||
}
|
}
|
||||||
|
|||||||
+9
-2
@@ -125,6 +125,13 @@ mod utf8;
|
|||||||
|
|
||||||
pub use self::ignored_any::IgnoredAny;
|
pub use self::ignored_any::IgnoredAny;
|
||||||
|
|
||||||
|
#[cfg(feature = "std")]
|
||||||
|
#[doc(no_inline)]
|
||||||
|
pub use std::error::Error as StdError;
|
||||||
|
#[cfg(not(feature = "std"))]
|
||||||
|
#[doc(no_inline)]
|
||||||
|
pub use std_error::Error as StdError;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
macro_rules! declare_error_trait {
|
macro_rules! declare_error_trait {
|
||||||
@@ -288,7 +295,7 @@ macro_rules! declare_error_trait {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
declare_error_trait!(Error: Sized + error::Error);
|
declare_error_trait!(Error: Sized + StdError);
|
||||||
|
|
||||||
#[cfg(not(feature = "std"))]
|
#[cfg(not(feature = "std"))]
|
||||||
declare_error_trait!(Error: Sized + Debug + Display);
|
declare_error_trait!(Error: Sized + Debug + Display);
|
||||||
@@ -787,7 +794,7 @@ where
|
|||||||
///
|
///
|
||||||
/// The role of this trait is to define the deserialization half of the [Serde
|
/// The role of this trait is to define the deserialization half of the [Serde
|
||||||
/// data model], which is a way to categorize every Rust data type into one of
|
/// data model], which is a way to categorize every Rust data type into one of
|
||||||
/// 29 possible types. Each method of the `Serializer` trait corresponds to one
|
/// 29 possible types. Each method of the `Deserializer` trait corresponds to one
|
||||||
/// of the types of the data model.
|
/// of the types of the data model.
|
||||||
///
|
///
|
||||||
/// Implementations of `Deserialize` map themselves into this data model by
|
/// Implementations of `Deserialize` map themselves into this data model by
|
||||||
|
|||||||
@@ -11,6 +11,9 @@ pub use self::string::from_utf8_lossy;
|
|||||||
#[cfg(any(feature = "alloc", feature = "std"))]
|
#[cfg(any(feature = "alloc", feature = "std"))]
|
||||||
pub use lib::{ToString, Vec};
|
pub use lib::{ToString, Vec};
|
||||||
|
|
||||||
|
#[cfg(core_try_from)]
|
||||||
|
pub use lib::convert::TryFrom;
|
||||||
|
|
||||||
mod string {
|
mod string {
|
||||||
use lib::*;
|
use lib::*;
|
||||||
|
|
||||||
|
|||||||
+9
-4
@@ -52,6 +52,7 @@
|
|||||||
//! *(deserialization only)*
|
//! *(deserialization only)*
|
||||||
//! - [Envy Store], a way to deserialize [AWS Parameter Store] parameters into
|
//! - [Envy Store], a way to deserialize [AWS Parameter Store] parameters into
|
||||||
//! Rust structs. *(deserialization only)*
|
//! Rust structs. *(deserialization only)*
|
||||||
|
//! - [Postcard], a `no_std` and embedded-systems friendly compact binary format.
|
||||||
//!
|
//!
|
||||||
//! [JSON]: https://github.com/serde-rs/json
|
//! [JSON]: https://github.com/serde-rs/json
|
||||||
//! [Bincode]: https://github.com/TyOverby/bincode
|
//! [Bincode]: https://github.com/TyOverby/bincode
|
||||||
@@ -69,11 +70,12 @@
|
|||||||
//! [Envy Store]: https://github.com/softprops/envy-store
|
//! [Envy Store]: https://github.com/softprops/envy-store
|
||||||
//! [Cargo]: http://doc.crates.io/manifest.html
|
//! [Cargo]: http://doc.crates.io/manifest.html
|
||||||
//! [AWS Parameter Store]: https://docs.aws.amazon.com/systems-manager/latest/userguide/systems-manager-paramstore.html
|
//! [AWS Parameter Store]: https://docs.aws.amazon.com/systems-manager/latest/userguide/systems-manager-paramstore.html
|
||||||
|
//! [Postcard]: https://github.com/jamesmunns/postcard
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
// 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.95")]
|
#![doc(html_root_url = "https://docs.rs/serde/1.0.100")]
|
||||||
// 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
|
||||||
@@ -81,7 +83,7 @@
|
|||||||
//
|
//
|
||||||
// https://github.com/serde-rs/serde/issues/812
|
// https://github.com/serde-rs/serde/issues/812
|
||||||
#![cfg_attr(feature = "unstable", feature(specialization, never_type))]
|
#![cfg_attr(feature = "unstable", feature(specialization, never_type))]
|
||||||
#![allow(unknown_lints, bare_trait_objects)]
|
#![allow(unknown_lints, bare_trait_objects, deprecated)]
|
||||||
#![cfg_attr(feature = "cargo-clippy", allow(renamed_and_removed_lints))]
|
#![cfg_attr(feature = "cargo-clippy", allow(renamed_and_removed_lints))]
|
||||||
#![cfg_attr(feature = "cargo-clippy", deny(clippy, clippy_pedantic))]
|
#![cfg_attr(feature = "cargo-clippy", deny(clippy, clippy_pedantic))]
|
||||||
// Ignored clippy and clippy_pedantic lints
|
// Ignored clippy and clippy_pedantic lints
|
||||||
@@ -212,12 +214,12 @@ mod lib {
|
|||||||
#[cfg(range_inclusive)]
|
#[cfg(range_inclusive)]
|
||||||
pub use self::core::ops::RangeInclusive;
|
pub use self::core::ops::RangeInclusive;
|
||||||
|
|
||||||
#[cfg(all(feature = "std", std_integer_atomics))]
|
#[cfg(all(feature = "std", std_atomic))]
|
||||||
pub use std::sync::atomic::{
|
pub use std::sync::atomic::{
|
||||||
AtomicBool, AtomicI16, AtomicI32, AtomicI8, AtomicIsize, AtomicU16, AtomicU32, AtomicU8,
|
AtomicBool, AtomicI16, AtomicI32, AtomicI8, AtomicIsize, AtomicU16, AtomicU32, AtomicU8,
|
||||||
AtomicUsize, Ordering,
|
AtomicUsize, Ordering,
|
||||||
};
|
};
|
||||||
#[cfg(all(feature = "std", std_integer_atomics, not(target_os = "emscripten")))]
|
#[cfg(all(feature = "std", std_atomic64))]
|
||||||
pub use std::sync::atomic::{AtomicI64, AtomicU64};
|
pub use std::sync::atomic::{AtomicI64, AtomicU64};
|
||||||
|
|
||||||
#[cfg(any(core_duration, feature = "std"))]
|
#[cfg(any(core_duration, feature = "std"))]
|
||||||
@@ -248,6 +250,9 @@ pub mod export;
|
|||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
pub mod private;
|
pub mod private;
|
||||||
|
|
||||||
|
#[cfg(not(feature = "std"))]
|
||||||
|
mod std_error;
|
||||||
|
|
||||||
// Re-export #[derive(Serialize, Deserialize)].
|
// Re-export #[derive(Serialize, Deserialize)].
|
||||||
//
|
//
|
||||||
// The reason re-exporting is not enabled by default is that disabling it would
|
// The reason re-exporting is not enabled by default is that disabling it would
|
||||||
|
|||||||
+17
-4
@@ -481,7 +481,6 @@ macro_rules! nonzero_integers {
|
|||||||
}
|
}
|
||||||
|
|
||||||
nonzero_integers! {
|
nonzero_integers! {
|
||||||
// Not including signed NonZeroI* since they might be removed
|
|
||||||
NonZeroU8,
|
NonZeroU8,
|
||||||
NonZeroU16,
|
NonZeroU16,
|
||||||
NonZeroU32,
|
NonZeroU32,
|
||||||
@@ -489,12 +488,26 @@ nonzero_integers! {
|
|||||||
NonZeroUsize,
|
NonZeroUsize,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(num_nonzero_signed)]
|
||||||
|
nonzero_integers! {
|
||||||
|
NonZeroI8,
|
||||||
|
NonZeroI16,
|
||||||
|
NonZeroI32,
|
||||||
|
NonZeroI64,
|
||||||
|
NonZeroIsize,
|
||||||
|
}
|
||||||
|
|
||||||
// Currently 128-bit integers do not work on Emscripten targets so we need an
|
// Currently 128-bit integers do not work on Emscripten targets so we need an
|
||||||
// additional `#[cfg]`
|
// additional `#[cfg]`
|
||||||
serde_if_integer128! {
|
serde_if_integer128! {
|
||||||
nonzero_integers! {
|
nonzero_integers! {
|
||||||
NonZeroU128,
|
NonZeroU128,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(num_nonzero_signed)]
|
||||||
|
nonzero_integers! {
|
||||||
|
NonZeroI128,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> Serialize for Cell<T>
|
impl<T> Serialize for Cell<T>
|
||||||
@@ -842,7 +855,7 @@ where
|
|||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#[cfg(all(feature = "std", std_integer_atomics))]
|
#[cfg(all(feature = "std", std_atomic))]
|
||||||
macro_rules! atomic_impl {
|
macro_rules! atomic_impl {
|
||||||
($($ty:ident)*) => {
|
($($ty:ident)*) => {
|
||||||
$(
|
$(
|
||||||
@@ -858,14 +871,14 @@ macro_rules! atomic_impl {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(all(feature = "std", std_integer_atomics))]
|
#[cfg(all(feature = "std", std_atomic))]
|
||||||
atomic_impl! {
|
atomic_impl! {
|
||||||
AtomicBool
|
AtomicBool
|
||||||
AtomicI8 AtomicI16 AtomicI32 AtomicIsize
|
AtomicI8 AtomicI16 AtomicI32 AtomicIsize
|
||||||
AtomicU8 AtomicU16 AtomicU32 AtomicUsize
|
AtomicU8 AtomicU16 AtomicU32 AtomicUsize
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(all(feature = "std", std_integer_atomics, not(target_os = "emscripten")))]
|
#[cfg(all(feature = "std", std_atomic64))]
|
||||||
atomic_impl! {
|
atomic_impl! {
|
||||||
AtomicI64 AtomicU64
|
AtomicI64 AtomicU64
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -114,6 +114,13 @@ mod impossible;
|
|||||||
|
|
||||||
pub use self::impossible::Impossible;
|
pub use self::impossible::Impossible;
|
||||||
|
|
||||||
|
#[cfg(feature = "std")]
|
||||||
|
#[doc(no_inline)]
|
||||||
|
pub use std::error::Error as StdError;
|
||||||
|
#[cfg(not(feature = "std"))]
|
||||||
|
#[doc(no_inline)]
|
||||||
|
pub use std_error::Error as StdError;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
macro_rules! declare_error_trait {
|
macro_rules! declare_error_trait {
|
||||||
@@ -172,7 +179,7 @@ macro_rules! declare_error_trait {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
declare_error_trait!(Error: Sized + error::Error);
|
declare_error_trait!(Error: Sized + StdError);
|
||||||
|
|
||||||
#[cfg(not(feature = "std"))]
|
#[cfg(not(feature = "std"))]
|
||||||
declare_error_trait!(Error: Sized + Debug + Display);
|
declare_error_trait!(Error: Sized + Debug + Display);
|
||||||
|
|||||||
@@ -0,0 +1,48 @@
|
|||||||
|
use lib::{Debug, Display};
|
||||||
|
|
||||||
|
/// Either a re-export of std::error::Error or a new identical trait, depending
|
||||||
|
/// on whether Serde's "std" feature is enabled.
|
||||||
|
///
|
||||||
|
/// Serde's error traits [`serde::ser::Error`] and [`serde::de::Error`] require
|
||||||
|
/// [`std::error::Error`] as a supertrait, but only when Serde is built with
|
||||||
|
/// "std" enabled. Data formats that don't care about no\_std support should
|
||||||
|
/// generally provide their error types with a `std::error::Error` impl
|
||||||
|
/// directly:
|
||||||
|
///
|
||||||
|
/// ```edition2018
|
||||||
|
/// #[derive(Debug)]
|
||||||
|
/// struct MySerError {...}
|
||||||
|
///
|
||||||
|
/// impl serde::ser::Error for MySerError {...}
|
||||||
|
///
|
||||||
|
/// impl std::fmt::Display for MySerError {...}
|
||||||
|
///
|
||||||
|
/// // We don't support no_std!
|
||||||
|
/// impl std::error::Error for MySerError {}
|
||||||
|
/// ```
|
||||||
|
///
|
||||||
|
/// Data formats that *do* support no\_std may either have a "std" feature of
|
||||||
|
/// their own:
|
||||||
|
///
|
||||||
|
/// ```toml
|
||||||
|
/// [features]
|
||||||
|
/// std = ["serde/std"]
|
||||||
|
/// ```
|
||||||
|
///
|
||||||
|
/// ```edition2018
|
||||||
|
/// #[cfg(feature = "std")]
|
||||||
|
/// impl std::error::Error for MySerError {}
|
||||||
|
/// ```
|
||||||
|
///
|
||||||
|
/// ... or else provide the std Error impl unconditionally via Serde's
|
||||||
|
/// re-export:
|
||||||
|
///
|
||||||
|
/// ```edition2018
|
||||||
|
/// impl serde::ser::StdError for MySerError {}
|
||||||
|
/// ```
|
||||||
|
pub trait Error: Debug + Display {
|
||||||
|
/// The underlying cause of this error, if any.
|
||||||
|
fn source(&self) -> Option<&(Error + 'static)> {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "serde_derive"
|
name = "serde_derive"
|
||||||
version = "1.0.95" # remember to update html_root_url
|
version = "1.0.100" # 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 OR Apache-2.0"
|
license = "MIT OR Apache-2.0"
|
||||||
description = "Macros 1.1 implementation of #[derive(Serialize, Deserialize)]"
|
description = "Macros 1.1 implementation of #[derive(Serialize, Deserialize)]"
|
||||||
@@ -24,9 +24,9 @@ name = "serde_derive"
|
|||||||
proc-macro = true
|
proc-macro = true
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
proc-macro2 = "0.4"
|
proc-macro2 = "1.0"
|
||||||
quote = "0.6.3"
|
quote = "1.0"
|
||||||
syn = { version = "0.15.22", features = ["visit"] }
|
syn = { version = "1.0", features = ["visit"] }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
serde = { version = "1.0", path = "../serde" }
|
serde = { version = "1.0", path = "../serde" }
|
||||||
|
|||||||
@@ -115,7 +115,7 @@ pub fn with_bound(
|
|||||||
impl<'ast> Visit<'ast> for FindTyParams<'ast> {
|
impl<'ast> Visit<'ast> for FindTyParams<'ast> {
|
||||||
fn visit_field(&mut self, field: &'ast syn::Field) {
|
fn visit_field(&mut self, field: &'ast syn::Field) {
|
||||||
if let syn::Type::Path(ref ty) = field.ty {
|
if let syn::Type::Path(ref ty) = field.ty {
|
||||||
if let Some(Pair::Punctuated(ref t, _)) = ty.path.segments.first() {
|
if let Some(Pair::Punctuated(ref t, _)) = ty.path.segments.pairs().next() {
|
||||||
if self.all_type_params.contains(&t.ident) {
|
if self.all_type_params.contains(&t.ident) {
|
||||||
self.associated_type_usage.push(ty);
|
self.associated_type_usage.push(ty);
|
||||||
}
|
}
|
||||||
@@ -126,7 +126,7 @@ pub fn with_bound(
|
|||||||
|
|
||||||
fn visit_path(&mut self, path: &'ast syn::Path) {
|
fn visit_path(&mut self, path: &'ast syn::Path) {
|
||||||
if let Some(seg) = path.segments.last() {
|
if let Some(seg) = path.segments.last() {
|
||||||
if seg.into_value().ident == "PhantomData" {
|
if seg.ident == "PhantomData" {
|
||||||
// Hardcoded exception, because PhantomData<T> implements
|
// Hardcoded exception, because PhantomData<T> implements
|
||||||
// Serialize and Deserialize whether or not T implements it.
|
// Serialize and Deserialize whether or not T implements it.
|
||||||
return;
|
return;
|
||||||
|
|||||||
+13
-2
@@ -20,7 +20,7 @@ pub fn expand_derive_deserialize(input: &syn::DeriveInput) -> Result<TokenStream
|
|||||||
None => return Err(ctxt.check().unwrap_err()),
|
None => return Err(ctxt.check().unwrap_err()),
|
||||||
};
|
};
|
||||||
precondition(&ctxt, &cont);
|
precondition(&ctxt, &cont);
|
||||||
try!(ctxt.check());
|
ctxt.check()?;
|
||||||
|
|
||||||
let ident = &cont.ident;
|
let ident = &cont.ident;
|
||||||
let params = Parameters::new(&cont);
|
let params = Parameters::new(&cont);
|
||||||
@@ -145,7 +145,7 @@ impl Parameters {
|
|||||||
/// Type name to use in error messages and `&'static str` arguments to
|
/// Type name to use in error messages and `&'static str` arguments to
|
||||||
/// various Deserializer methods.
|
/// various Deserializer methods.
|
||||||
fn type_name(&self) -> String {
|
fn type_name(&self) -> String {
|
||||||
self.this.segments.last().unwrap().value().ident.to_string()
|
self.this.segments.last().unwrap().ident.to_string()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -269,6 +269,8 @@ fn deserialize_body(cont: &Container, params: &Parameters) -> Fragment {
|
|||||||
deserialize_transparent(cont, params)
|
deserialize_transparent(cont, params)
|
||||||
} else if let Some(type_from) = cont.attrs.type_from() {
|
} else if let Some(type_from) = cont.attrs.type_from() {
|
||||||
deserialize_from(type_from)
|
deserialize_from(type_from)
|
||||||
|
} else if let Some(type_try_from) = cont.attrs.type_try_from() {
|
||||||
|
deserialize_try_from(type_try_from)
|
||||||
} else if let attr::Identifier::No = cont.attrs.identifier() {
|
} else if let attr::Identifier::No = cont.attrs.identifier() {
|
||||||
match cont.data {
|
match cont.data {
|
||||||
Data::Enum(ref variants) => deserialize_enum(params, variants, &cont.attrs),
|
Data::Enum(ref variants) => deserialize_enum(params, variants, &cont.attrs),
|
||||||
@@ -298,6 +300,7 @@ fn deserialize_in_place_body(cont: &Container, params: &Parameters) -> Option<St
|
|||||||
|
|
||||||
if cont.attrs.transparent()
|
if cont.attrs.transparent()
|
||||||
|| cont.attrs.type_from().is_some()
|
|| cont.attrs.type_from().is_some()
|
||||||
|
|| cont.attrs.type_try_from().is_some()
|
||||||
|| cont.attrs.identifier().is_some()
|
|| cont.attrs.identifier().is_some()
|
||||||
|| cont
|
|| cont
|
||||||
.data
|
.data
|
||||||
@@ -390,6 +393,14 @@ fn deserialize_from(type_from: &syn::Type) -> Fragment {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn deserialize_try_from(type_try_from: &syn::Type) -> Fragment {
|
||||||
|
quote_block! {
|
||||||
|
_serde::export::Result::and_then(
|
||||||
|
<#type_try_from as _serde::Deserialize>::deserialize(__deserializer),
|
||||||
|
|v| _serde::export::TryFrom::try_from(v).map_err(_serde::de::Error::custom))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn deserialize_unit_struct(params: &Parameters, cattrs: &attr::Container) -> Fragment {
|
fn deserialize_unit_struct(params: &Parameters, cattrs: &attr::Container) -> Fragment {
|
||||||
let this = ¶ms.this;
|
let this = ¶ms.this;
|
||||||
let type_name = cattrs.name().deserialize_name();
|
let type_name = cattrs.name().deserialize_name();
|
||||||
|
|||||||
+268
-240
File diff suppressed because it is too large
Load Diff
@@ -13,6 +13,7 @@ pub fn check(cx: &Ctxt, cont: &mut Container, derive: Derive) {
|
|||||||
check_internal_tag_field_name_conflict(cx, cont);
|
check_internal_tag_field_name_conflict(cx, cont);
|
||||||
check_adjacent_tag_conflict(cx, cont);
|
check_adjacent_tag_conflict(cx, cont);
|
||||||
check_transparent(cx, cont, derive);
|
check_transparent(cx, cont, derive);
|
||||||
|
check_from_and_try_from(cx, cont);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Getters are only allowed inside structs (not enums) with the `remote`
|
/// Getters are only allowed inside structs (not enums) with the `remote`
|
||||||
@@ -330,6 +331,13 @@ fn check_transparent(cx: &Ctxt, cont: &mut Container, derive: Derive) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if cont.attrs.type_try_from().is_some() {
|
||||||
|
cx.error_spanned_by(
|
||||||
|
cont.original,
|
||||||
|
"#[serde(transparent)] is not allowed with #[serde(try_from = \"...\")]",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
if cont.attrs.type_into().is_some() {
|
if cont.attrs.type_into().is_some() {
|
||||||
cx.error_spanned_by(
|
cx.error_spanned_by(
|
||||||
cont.original,
|
cont.original,
|
||||||
@@ -399,7 +407,7 @@ fn member_message(member: &Member) -> String {
|
|||||||
fn allow_transparent(field: &Field, derive: Derive) -> bool {
|
fn allow_transparent(field: &Field, derive: Derive) -> bool {
|
||||||
if let Type::Path(ref ty) = *field.ty {
|
if let Type::Path(ref ty) = *field.ty {
|
||||||
if let Some(seg) = ty.path.segments.last() {
|
if let Some(seg) = ty.path.segments.last() {
|
||||||
if seg.into_value().ident == "PhantomData" {
|
if seg.ident == "PhantomData" {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -410,3 +418,12 @@ fn allow_transparent(field: &Field, derive: Derive) -> bool {
|
|||||||
Derive::Deserialize => !field.attrs.skip_deserializing() && field.attrs.default().is_none(),
|
Derive::Deserialize => !field.attrs.skip_deserializing() && field.attrs.default().is_none(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn check_from_and_try_from(cx: &Ctxt, cont: &mut Container) {
|
||||||
|
if cont.attrs.type_from().is_some() && cont.attrs.type_try_from().is_some() {
|
||||||
|
cx.error_spanned_by(
|
||||||
|
cont.original,
|
||||||
|
"#[serde(from = \"...\")] and #[serde(try_from = \"...\")] conflict with each other",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ pub use self::ctxt::Ctxt;
|
|||||||
|
|
||||||
mod case;
|
mod case;
|
||||||
mod check;
|
mod check;
|
||||||
|
mod symbol;
|
||||||
|
|
||||||
#[derive(Copy, Clone)]
|
#[derive(Copy, Clone)]
|
||||||
pub enum Derive {
|
pub enum Derive {
|
||||||
|
|||||||
@@ -0,0 +1,67 @@
|
|||||||
|
use std::fmt::{self, Display};
|
||||||
|
use syn::{Ident, Path};
|
||||||
|
|
||||||
|
#[derive(Copy, Clone)]
|
||||||
|
pub struct Symbol(&'static str);
|
||||||
|
|
||||||
|
pub const ALIAS: Symbol = Symbol("alias");
|
||||||
|
pub const BORROW: Symbol = Symbol("borrow");
|
||||||
|
pub const BOUND: Symbol = Symbol("bound");
|
||||||
|
pub const CONTENT: Symbol = Symbol("content");
|
||||||
|
pub const CRATE: Symbol = Symbol("crate");
|
||||||
|
pub const DEFAULT: Symbol = Symbol("default");
|
||||||
|
pub const DENY_UNKNOWN_FIELDS: Symbol = Symbol("deny_unknown_fields");
|
||||||
|
pub const DESERIALIZE: Symbol = Symbol("deserialize");
|
||||||
|
pub const DESERIALIZE_WITH: Symbol = Symbol("deserialize_with");
|
||||||
|
pub const FIELD_IDENTIFIER: Symbol = Symbol("field_identifier");
|
||||||
|
pub const FLATTEN: Symbol = Symbol("flatten");
|
||||||
|
pub const FROM: Symbol = Symbol("from");
|
||||||
|
pub const GETTER: Symbol = Symbol("getter");
|
||||||
|
pub const INTO: Symbol = Symbol("into");
|
||||||
|
pub const OTHER: Symbol = Symbol("other");
|
||||||
|
pub const REMOTE: Symbol = Symbol("remote");
|
||||||
|
pub const RENAME: Symbol = Symbol("rename");
|
||||||
|
pub const RENAME_ALL: Symbol = Symbol("rename_all");
|
||||||
|
pub const SERDE: Symbol = Symbol("serde");
|
||||||
|
pub const SERIALIZE: Symbol = Symbol("serialize");
|
||||||
|
pub const SERIALIZE_WITH: Symbol = Symbol("serialize_with");
|
||||||
|
pub const SKIP: Symbol = Symbol("skip");
|
||||||
|
pub const SKIP_DESERIALIZING: Symbol = Symbol("skip_deserializing");
|
||||||
|
pub const SKIP_SERIALIZING: Symbol = Symbol("skip_serializing");
|
||||||
|
pub const SKIP_SERIALIZING_IF: Symbol = Symbol("skip_serializing_if");
|
||||||
|
pub const TAG: Symbol = Symbol("tag");
|
||||||
|
pub const TRANSPARENT: Symbol = Symbol("transparent");
|
||||||
|
pub const TRY_FROM: Symbol = Symbol("try_from");
|
||||||
|
pub const UNTAGGED: Symbol = Symbol("untagged");
|
||||||
|
pub const VARIANT_IDENTIFIER: Symbol = Symbol("variant_identifier");
|
||||||
|
pub const WITH: Symbol = Symbol("with");
|
||||||
|
|
||||||
|
impl PartialEq<Symbol> for Ident {
|
||||||
|
fn eq(&self, word: &Symbol) -> bool {
|
||||||
|
self == word.0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> PartialEq<Symbol> for &'a Ident {
|
||||||
|
fn eq(&self, word: &Symbol) -> bool {
|
||||||
|
*self == word.0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl PartialEq<Symbol> for Path {
|
||||||
|
fn eq(&self, word: &Symbol) -> bool {
|
||||||
|
self.is_ident(word.0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> PartialEq<Symbol> for &'a Path {
|
||||||
|
fn eq(&self, word: &Symbol) -> bool {
|
||||||
|
self.is_ident(word.0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Display for Symbol {
|
||||||
|
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||||
|
formatter.write_str(self.0)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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.95")]
|
#![doc(html_root_url = "https://docs.rs/serde_derive/1.0.100")]
|
||||||
#![allow(unknown_lints, bare_trait_objects)]
|
#![allow(unknown_lints, bare_trait_objects)]
|
||||||
#![cfg_attr(feature = "cargo-clippy", allow(renamed_and_removed_lints))]
|
#![cfg_attr(feature = "cargo-clippy", allow(renamed_and_removed_lints))]
|
||||||
#![cfg_attr(feature = "cargo-clippy", deny(clippy, clippy_pedantic))]
|
#![cfg_attr(feature = "cargo-clippy", deny(clippy, clippy_pedantic))]
|
||||||
|
|||||||
+8
-20
@@ -16,7 +16,7 @@ pub fn expand_derive_serialize(input: &syn::DeriveInput) -> Result<TokenStream,
|
|||||||
None => return Err(ctxt.check().unwrap_err()),
|
None => return Err(ctxt.check().unwrap_err()),
|
||||||
};
|
};
|
||||||
precondition(&ctxt, &cont);
|
precondition(&ctxt, &cont);
|
||||||
try!(ctxt.check());
|
ctxt.check()?;
|
||||||
|
|
||||||
let ident = &cont.ident;
|
let ident = &cont.ident;
|
||||||
let params = Parameters::new(&cont);
|
let params = Parameters::new(&cont);
|
||||||
@@ -116,7 +116,7 @@ impl Parameters {
|
|||||||
/// Type name to use in error messages and `&'static str` arguments to
|
/// Type name to use in error messages and `&'static str` arguments to
|
||||||
/// various Serializer methods.
|
/// various Serializer methods.
|
||||||
fn type_name(&self) -> String {
|
fn type_name(&self) -> String {
|
||||||
self.this.segments.last().unwrap().value().ident.to_string()
|
self.this.segments.last().unwrap().ident.to_string()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1267,15 +1267,9 @@ enum StructTrait {
|
|||||||
impl StructTrait {
|
impl StructTrait {
|
||||||
fn serialize_field(&self, span: Span) -> TokenStream {
|
fn serialize_field(&self, span: Span) -> TokenStream {
|
||||||
match *self {
|
match *self {
|
||||||
StructTrait::SerializeMap => {
|
StructTrait::SerializeMap => quote_spanned!(span=> _serde::ser::SerializeMap::serialize_entry),
|
||||||
quote_spanned!(span=> _serde::ser::SerializeMap::serialize_entry)
|
StructTrait::SerializeStruct => quote_spanned!(span=> _serde::ser::SerializeStruct::serialize_field),
|
||||||
}
|
StructTrait::SerializeStructVariant => quote_spanned!(span=> _serde::ser::SerializeStructVariant::serialize_field),
|
||||||
StructTrait::SerializeStruct => {
|
|
||||||
quote_spanned!(span=> _serde::ser::SerializeStruct::serialize_field)
|
|
||||||
}
|
|
||||||
StructTrait::SerializeStructVariant => {
|
|
||||||
quote_spanned!(span=> _serde::ser::SerializeStructVariant::serialize_field)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1301,15 +1295,9 @@ enum TupleTrait {
|
|||||||
impl TupleTrait {
|
impl TupleTrait {
|
||||||
fn serialize_element(&self, span: Span) -> TokenStream {
|
fn serialize_element(&self, span: Span) -> TokenStream {
|
||||||
match *self {
|
match *self {
|
||||||
TupleTrait::SerializeTuple => {
|
TupleTrait::SerializeTuple => quote_spanned!(span=> _serde::ser::SerializeTuple::serialize_element),
|
||||||
quote_spanned!(span=> _serde::ser::SerializeTuple::serialize_element)
|
TupleTrait::SerializeTupleStruct => quote_spanned!(span=> _serde::ser::SerializeTupleStruct::serialize_field),
|
||||||
}
|
TupleTrait::SerializeTupleVariant => quote_spanned!(span=> _serde::ser::SerializeTupleVariant::serialize_field),
|
||||||
TupleTrait::SerializeTupleStruct => {
|
|
||||||
quote_spanned!(span=> _serde::ser::SerializeTupleStruct::serialize_field)
|
|
||||||
}
|
|
||||||
TupleTrait::SerializeTupleVariant => {
|
|
||||||
quote_spanned!(span=> _serde::ser::SerializeTupleVariant::serialize_field)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,9 +14,9 @@ include = ["Cargo.toml", "lib.rs", "src/**/*.rs", "LICENSE-APACHE", "LICENSE-MIT
|
|||||||
path = "lib.rs"
|
path = "lib.rs"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
proc-macro2 = "0.4"
|
proc-macro2 = "1.0"
|
||||||
quote = "0.6.3"
|
quote = "1.0"
|
||||||
syn = { version = "0.15", default-features = false, features = ["derive", "parsing", "printing", "clone-impls"] }
|
syn = { version = "1.0", default-features = false, features = ["derive", "parsing", "printing", "clone-impls"] }
|
||||||
|
|
||||||
[badges]
|
[badges]
|
||||||
travis-ci = { repository = "serde-rs/serde" }
|
travis-ci = { repository = "serde-rs/serde" }
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "serde_test"
|
name = "serde_test"
|
||||||
version = "1.0.95" # remember to update html_root_url
|
version = "1.0.100" # 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 OR Apache-2.0"
|
license = "MIT OR Apache-2.0"
|
||||||
description = "Token De/Serializer for testing De/Serialize implementations"
|
description = "Token De/Serializer for testing De/Serialize implementations"
|
||||||
|
|||||||
@@ -89,11 +89,11 @@ impl<'de> Deserializer<'de> {
|
|||||||
where
|
where
|
||||||
V: Visitor<'de>,
|
V: Visitor<'de>,
|
||||||
{
|
{
|
||||||
let value = try!(visitor.visit_seq(DeserializerSeqVisitor {
|
let value = visitor.visit_seq(DeserializerSeqVisitor {
|
||||||
de: self,
|
de: self,
|
||||||
len: len,
|
len: len,
|
||||||
end: end,
|
end: end,
|
||||||
},));
|
})?;
|
||||||
assert_next_token!(self, end);
|
assert_next_token!(self, end);
|
||||||
Ok(value)
|
Ok(value)
|
||||||
}
|
}
|
||||||
@@ -107,11 +107,11 @@ impl<'de> Deserializer<'de> {
|
|||||||
where
|
where
|
||||||
V: Visitor<'de>,
|
V: Visitor<'de>,
|
||||||
{
|
{
|
||||||
let value = try!(visitor.visit_map(DeserializerMapVisitor {
|
let value = visitor.visit_map(DeserializerMapVisitor {
|
||||||
de: self,
|
de: self,
|
||||||
len: len,
|
len: len,
|
||||||
end: end,
|
end: end,
|
||||||
},));
|
})?;
|
||||||
assert_next_token!(self, end);
|
assert_next_token!(self, end);
|
||||||
Ok(value)
|
Ok(value)
|
||||||
}
|
}
|
||||||
@@ -456,11 +456,11 @@ impl<'de, 'a> EnumAccess<'de> for DeserializerEnumVisitor<'a, 'de> {
|
|||||||
| Token::TupleVariant { variant: v, .. }
|
| Token::TupleVariant { variant: v, .. }
|
||||||
| Token::StructVariant { variant: v, .. } => {
|
| Token::StructVariant { variant: v, .. } => {
|
||||||
let de = v.into_deserializer();
|
let de = v.into_deserializer();
|
||||||
let value = try!(seed.deserialize(de));
|
let value = seed.deserialize(de)?;
|
||||||
Ok((value, self))
|
Ok((value, self))
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
let value = try!(seed.deserialize(&mut *self.de));
|
let value = seed.deserialize(&mut *self.de)?;
|
||||||
Ok((value, self))
|
Ok((value, self))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -613,7 +613,7 @@ impl<'de, 'a> MapAccess<'de> for EnumMapVisitor<'a, 'de> {
|
|||||||
len: None,
|
len: None,
|
||||||
end: Token::TupleVariantEnd,
|
end: Token::TupleVariantEnd,
|
||||||
};
|
};
|
||||||
try!(seed.deserialize(SeqAccessDeserializer::new(visitor)))
|
seed.deserialize(SeqAccessDeserializer::new(visitor))?
|
||||||
};
|
};
|
||||||
assert_next_token!(self.de, Token::TupleVariantEnd);
|
assert_next_token!(self.de, Token::TupleVariantEnd);
|
||||||
Ok(value)
|
Ok(value)
|
||||||
@@ -625,7 +625,7 @@ impl<'de, 'a> MapAccess<'de> for EnumMapVisitor<'a, 'de> {
|
|||||||
len: None,
|
len: None,
|
||||||
end: Token::StructVariantEnd,
|
end: Token::StructVariantEnd,
|
||||||
};
|
};
|
||||||
try!(seed.deserialize(MapAccessDeserializer::new(visitor)))
|
seed.deserialize(MapAccessDeserializer::new(visitor))?
|
||||||
};
|
};
|
||||||
assert_next_token!(self.de, Token::StructVariantEnd);
|
assert_next_token!(self.de, Token::StructVariantEnd);
|
||||||
Ok(value)
|
Ok(value)
|
||||||
|
|||||||
@@ -144,7 +144,7 @@
|
|||||||
//! # }
|
//! # }
|
||||||
//! ```
|
//! ```
|
||||||
|
|
||||||
#![doc(html_root_url = "https://docs.rs/serde_test/1.0.95")]
|
#![doc(html_root_url = "https://docs.rs/serde_test/1.0.100")]
|
||||||
#![cfg_attr(feature = "cargo-clippy", allow(renamed_and_removed_lints))]
|
#![cfg_attr(feature = "cargo-clippy", allow(renamed_and_removed_lints))]
|
||||||
#![cfg_attr(feature = "cargo-clippy", deny(clippy, clippy_pedantic))]
|
#![cfg_attr(feature = "cargo-clippy", deny(clippy, clippy_pedantic))]
|
||||||
// Ignored clippy lints
|
// Ignored clippy lints
|
||||||
|
|||||||
@@ -427,7 +427,7 @@ impl<'s, 'a> ser::SerializeStruct for &'s mut Serializer<'a> {
|
|||||||
where
|
where
|
||||||
T: Serialize,
|
T: Serialize,
|
||||||
{
|
{
|
||||||
try!(key.serialize(&mut **self));
|
key.serialize(&mut **self)?;
|
||||||
value.serialize(&mut **self)
|
value.serialize(&mut **self)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -449,7 +449,7 @@ impl<'s, 'a> ser::SerializeStructVariant for Variant<'s, 'a> {
|
|||||||
where
|
where
|
||||||
T: Serialize,
|
T: Serialize,
|
||||||
{
|
{
|
||||||
try!(key.serialize(&mut *self.ser));
|
key.serialize(&mut *self.ser)?;
|
||||||
value.serialize(&mut *self.ser)
|
value.serialize(&mut *self.ser)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ use serde::de::{self, MapAccess, Unexpected, Visitor};
|
|||||||
use serde::{Deserialize, Deserializer, Serialize, Serializer};
|
use serde::{Deserialize, Deserializer, Serialize, Serializer};
|
||||||
|
|
||||||
use std::collections::{BTreeMap, HashMap};
|
use std::collections::{BTreeMap, HashMap};
|
||||||
|
use std::convert::TryFrom;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
|
|
||||||
@@ -1588,14 +1589,35 @@ impl From<Option<u32>> for EnumToU32 {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Deserialize, PartialEq, Debug)]
|
||||||
|
#[serde(try_from = "u32")]
|
||||||
|
enum TryFromU32 {
|
||||||
|
One,
|
||||||
|
Two,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl TryFrom<u32> for TryFromU32 {
|
||||||
|
type Error = String;
|
||||||
|
|
||||||
|
fn try_from(value: u32) -> Result<Self, Self::Error> {
|
||||||
|
match value {
|
||||||
|
1 => Ok(TryFromU32::One),
|
||||||
|
2 => Ok(TryFromU32::Two),
|
||||||
|
_ => Err("out of range".to_owned()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_from_into_traits() {
|
fn test_from_into_traits() {
|
||||||
assert_ser_tokens::<EnumToU32>(&EnumToU32::One, &[Token::Some, Token::U32(1)]);
|
assert_ser_tokens(&EnumToU32::One, &[Token::Some, Token::U32(1)]);
|
||||||
assert_ser_tokens::<EnumToU32>(&EnumToU32::Nothing, &[Token::None]);
|
assert_ser_tokens(&EnumToU32::Nothing, &[Token::None]);
|
||||||
assert_de_tokens::<EnumToU32>(&EnumToU32::Two, &[Token::Some, Token::U32(2)]);
|
assert_de_tokens(&EnumToU32::Two, &[Token::Some, Token::U32(2)]);
|
||||||
assert_ser_tokens::<StructFromEnum>(&StructFromEnum(Some(5)), &[Token::None]);
|
assert_ser_tokens(&StructFromEnum(Some(5)), &[Token::None]);
|
||||||
assert_ser_tokens::<StructFromEnum>(&StructFromEnum(None), &[Token::None]);
|
assert_ser_tokens(&StructFromEnum(None), &[Token::None]);
|
||||||
assert_de_tokens::<StructFromEnum>(&StructFromEnum(Some(2)), &[Token::Some, Token::U32(2)]);
|
assert_de_tokens(&StructFromEnum(Some(2)), &[Token::Some, Token::U32(2)]);
|
||||||
|
assert_de_tokens(&TryFromU32::Two, &[Token::U32(2)]);
|
||||||
|
assert_de_tokens_error::<TryFromU32>(&[Token::U32(5)], "out of range");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ use std::sync::atomic::{
|
|||||||
use std::sync::{Arc, Weak as ArcWeak};
|
use std::sync::{Arc, Weak as ArcWeak};
|
||||||
use std::time::{Duration, UNIX_EPOCH};
|
use std::time::{Duration, UNIX_EPOCH};
|
||||||
|
|
||||||
#[cfg(not(target_os = "emscripten"))]
|
#[cfg(target_arch = "x86_64")]
|
||||||
use std::sync::atomic::{AtomicI64, AtomicU64};
|
use std::sync::atomic::{AtomicI64, AtomicU64};
|
||||||
|
|
||||||
use fnv::FnvHasher;
|
use fnv::FnvHasher;
|
||||||
@@ -1181,7 +1181,7 @@ fn test_atomics() {
|
|||||||
test(AtomicU32::load, 131072u32, Token::U32(131072u32));
|
test(AtomicU32::load, 131072u32, Token::U32(131072u32));
|
||||||
test(AtomicUsize::load, 131072usize, Token::U32(131072));
|
test(AtomicUsize::load, 131072usize, Token::U32(131072));
|
||||||
|
|
||||||
#[cfg(not(target_os = "emscripten"))]
|
#[cfg(target_arch = "x86_64")]
|
||||||
{
|
{
|
||||||
test(AtomicI64::load, -8589934592, Token::I64(-8589934592));
|
test(AtomicI64::load, -8589934592, Token::I64(-8589934592));
|
||||||
test(AtomicU64::load, 8589934592u64, Token::U64(8589934592));
|
test(AtomicU64::load, 8589934592u64, Token::U64(8589934592));
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ use std::time::{Duration, UNIX_EPOCH};
|
|||||||
|
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
use std::str;
|
use std::str;
|
||||||
#[cfg(not(target_os = "emscripten"))]
|
#[cfg(target_arch = "x86_64")]
|
||||||
use std::sync::atomic::{AtomicI64, AtomicU64};
|
use std::sync::atomic::{AtomicI64, AtomicU64};
|
||||||
|
|
||||||
use fnv::FnvHasher;
|
use fnv::FnvHasher;
|
||||||
@@ -504,7 +504,7 @@ declare_tests! {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(target_os = "emscripten"))]
|
#[cfg(target_arch = "x86_64")]
|
||||||
declare_tests! {
|
declare_tests! {
|
||||||
test_atomic64 {
|
test_atomic64 {
|
||||||
AtomicI64::new(-4295032832i64) => &[Token::I64(-4295032832i64)],
|
AtomicI64::new(-4295032832i64) => &[Token::I64(-4295032832i64)],
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
use serde_derive::Serialize;
|
||||||
|
|
||||||
|
#[derive(Serialize)]
|
||||||
|
#[serde(from = "u64", try_from = "u64")]
|
||||||
|
struct S {
|
||||||
|
a: u8,
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
error: #[serde(from = "...")] and #[serde(try_from = "...")] conflict with each other
|
||||||
|
--> $DIR/from-try-from.rs:4:1
|
||||||
|
|
|
||||||
|
4 | / #[serde(from = "u64", try_from = "u64")]
|
||||||
|
5 | | struct S {
|
||||||
|
6 | | a: u8,
|
||||||
|
7 | | }
|
||||||
|
| |_^
|
||||||
@@ -2,6 +2,9 @@ error[E0308]: mismatched types
|
|||||||
--> $DIR/wrong_de.rs:7:10
|
--> $DIR/wrong_de.rs:7:10
|
||||||
|
|
|
|
||||||
7 | #[derive(Deserialize)]
|
7 | #[derive(Deserialize)]
|
||||||
| ^^^^^^^^^^^ expected u16, found u8
|
| ^^^^^^^^^^^
|
||||||
|
| |
|
||||||
|
| expected u16, found u8
|
||||||
|
| help: you can convert an `u8` to `u16`: `Deserialize.into()`
|
||||||
|
|
||||||
For more information about this error, try `rustc --explain E0308`.
|
For more information about this error, try `rustc --explain E0308`.
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
use serde_derive::Serialize;
|
||||||
|
|
||||||
|
#[derive(Serialize)]
|
||||||
|
#[serde(transparent, try_from = "u64")]
|
||||||
|
struct S {
|
||||||
|
a: u8,
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
error: #[serde(transparent)] is not allowed with #[serde(try_from = "...")]
|
||||||
|
--> $DIR/with_try_from.rs:4:1
|
||||||
|
|
|
||||||
|
4 | / #[serde(transparent, try_from = "u64")]
|
||||||
|
5 | | struct S {
|
||||||
|
6 | | a: u8,
|
||||||
|
7 | | }
|
||||||
|
| |_^
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
use serde_derive::Deserialize;
|
||||||
|
|
||||||
|
#[derive(Deserialize)]
|
||||||
|
#[serde(try_from = "Option<T")]
|
||||||
|
enum TestOne {
|
||||||
|
Testing,
|
||||||
|
One,
|
||||||
|
Two,
|
||||||
|
Three,
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
error: failed to parse type: try_from = "Option<T"
|
||||||
|
--> $DIR/try_from.rs:4:20
|
||||||
|
|
|
||||||
|
4 | #[serde(try_from = "Option<T")]
|
||||||
|
| ^^^^^^^^^^
|
||||||
Reference in New Issue
Block a user