mirror of
https://github.com/pezkuwichain/serde.git
synced 2026-04-27 20:27:57 +00:00
Compare commits
13 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| ad680cbd44 | |||
| ff0cfb1f1f | |||
| 9b08915a18 | |||
| 501aa3ee1d | |||
| eebf0f8db8 | |||
| a7e4911ddb | |||
| eb08f037f5 | |||
| aa03fd5d1a | |||
| e198afb0c1 | |||
| bc8de251cf | |||
| 99e8686189 | |||
| 826f656e28 | |||
| ab7c003b64 |
+52
-31
@@ -1,45 +1,66 @@
|
|||||||
# Contributing to Serde
|
# Contributing to Serde
|
||||||
|
|
||||||
Serde welcomes contribution from everyone. Here are the guidelines if you are
|
Serde welcomes contribution from everyone in the form of suggestions, bug
|
||||||
thinking of helping us:
|
reports, pull requests, and feedback. This document gives some guidance if you
|
||||||
|
are thinking of helping us.
|
||||||
|
|
||||||
## Contributions
|
Please reach out here in a GitHub issue or in the #serde IRC channel on
|
||||||
|
[`irc.mozilla.org`] if we can do anything to help you contribute.
|
||||||
|
|
||||||
Contributions to Serde or its dependencies should be made in the form of GitHub
|
[`irc.mozilla.org`]: https://wiki.mozilla.org/IRC
|
||||||
pull requests. Each pull request will be reviewed by a core contributor
|
|
||||||
(someone with permission to land patches) and either landed in the main tree or
|
|
||||||
given feedback for changes that would be required. All contributions should
|
|
||||||
follow this format, even those from core contributors.
|
|
||||||
|
|
||||||
Should you wish to work on an issue, please claim it first by commenting on
|
## Submitting bug reports and feature requests
|
||||||
the GitHub issue that you want to work on it. This is to prevent duplicated
|
|
||||||
efforts from contributors on the same issue.
|
|
||||||
|
|
||||||
## Pull Request Checklist
|
Serde development is spread across lots of repositories, but this serde-rs/serde
|
||||||
|
repository is always a safe choice for opening any issues related to Serde.
|
||||||
|
|
||||||
- Branch from the master branch and, if needed, rebase to the current master
|
When reporting a bug or asking for help, please include enough details so that
|
||||||
branch before submitting your pull request. If it doesn't merge cleanly with
|
the people helping you can reproduce the behavior you are seeing. For some tips
|
||||||
master you may be asked to rebase your changes.
|
on how to approach this, read about how to produce a [Minimal, Complete, and
|
||||||
|
Verifiable example].
|
||||||
|
|
||||||
- Commits should be as small as possible, while ensuring that each commit is
|
[Minimal, Complete, and Verifiable example]: https://stackoverflow.com/help/mcve
|
||||||
correct independently (i.e., each commit should compile and pass tests).
|
|
||||||
|
|
||||||
- If your patch is not getting reviewed or you need a specific person to review
|
When making a feature request, please make it clear what problem you intend to
|
||||||
it, you can @-reply a reviewer asking for a review in the pull request or a
|
solve with the feature, any ideas for how Serde could support solving that
|
||||||
comment, or you can ask for a review in `#serde` on `irc.mozilla.org`.
|
problem, any possible alternatives, and any disadvantages.
|
||||||
|
|
||||||
- Add tests relevant to the fixed bug or new feature.
|
## Running the test suite
|
||||||
|
|
||||||
|
We encourage you to check that the test suite passes locally before submitting a
|
||||||
|
pull request with your changes. If anything does not pass, typically it will be
|
||||||
|
easier to iterate and fix it locally than waiting for the CI servers to run
|
||||||
|
tests for you.
|
||||||
|
|
||||||
|
##### In the [`serde`] directory
|
||||||
|
|
||||||
|
```sh
|
||||||
|
# Test all the example code in Serde documentation
|
||||||
|
cargo test
|
||||||
|
```
|
||||||
|
|
||||||
|
##### In the [`test_suite/deps`] directory
|
||||||
|
|
||||||
|
```sh
|
||||||
|
# This is a prerequisite for running the full test suite
|
||||||
|
cargo clean && cargo update && cargo build
|
||||||
|
```
|
||||||
|
|
||||||
|
##### In the [`test_suite`] directory
|
||||||
|
|
||||||
|
```sh
|
||||||
|
# Run the full test suite, including tests of unstable functionality
|
||||||
|
cargo test --features unstable
|
||||||
|
```
|
||||||
|
|
||||||
|
[`serde`]: https://github.com/serde-rs/serde/tree/master/serde
|
||||||
|
[`test_suite/deps`]: https://github.com/serde-rs/serde/tree/master/test_suite/deps
|
||||||
|
[`test_suite`]: https://github.com/serde-rs/serde/tree/master/test_suite
|
||||||
|
|
||||||
## Conduct
|
## Conduct
|
||||||
|
|
||||||
In all Serde-related forums, we follow the [Rust Code of
|
In all Serde-related forums, we follow the [Rust Code of Conduct]. For
|
||||||
Conduct](https://www.rust-lang.org/conduct.html). For escalation or moderation
|
escalation or moderation issues please contact Erick (erick.tryzelaar@gmail.com)
|
||||||
issues, please contact Erick (erick.tryzelaar@gmail.com) instead of the Rust
|
instead of the Rust moderation team.
|
||||||
moderation team.
|
|
||||||
|
|
||||||
## Communication
|
[Rust Code of Conduct]: https://www.rust-lang.org/conduct.html
|
||||||
|
|
||||||
Beyond opening tickets on the
|
|
||||||
[serde-rs/serde](https://github.com/serde-rs/serde) project, Serde contributors
|
|
||||||
frequent the `#serde` channel on
|
|
||||||
[`irc.mozilla.org`](https://wiki.mozilla.org/IRC).
|
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "serde"
|
name = "serde"
|
||||||
version = "1.0.16" # remember to update html_root_url
|
version = "1.0.17" # remember to update html_root_url
|
||||||
authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>", "David Tolnay <dtolnay@gmail.com>"]
|
authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>", "David Tolnay <dtolnay@gmail.com>"]
|
||||||
license = "MIT/Apache-2.0"
|
license = "MIT/Apache-2.0"
|
||||||
description = "A generic serialization/deserialization framework"
|
description = "A generic serialization/deserialization framework"
|
||||||
|
|||||||
@@ -1825,3 +1825,18 @@ where
|
|||||||
deserializer.deserialize_enum("Result", VARIANTS, ResultVisitor(PhantomData))
|
deserializer.deserialize_enum("Result", VARIANTS, ResultVisitor(PhantomData))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#[cfg(feature = "std")]
|
||||||
|
impl<'de, T> Deserialize<'de> for Wrapping<T>
|
||||||
|
where
|
||||||
|
T: Deserialize<'de>
|
||||||
|
{
|
||||||
|
fn deserialize<D>(deserializer: D) -> Result<Wrapping<T>, D::Error>
|
||||||
|
where
|
||||||
|
D: Deserializer<'de>,
|
||||||
|
{
|
||||||
|
Deserialize::deserialize(deserializer).map(Wrapping)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
+5
-3
@@ -1027,6 +1027,10 @@ pub trait Deserializer<'de>: Sized {
|
|||||||
/// #
|
/// #
|
||||||
/// # struct Timestamp;
|
/// # struct Timestamp;
|
||||||
/// #
|
/// #
|
||||||
|
/// # impl Timestamp {
|
||||||
|
/// # const EPOCH: Timestamp = Timestamp;
|
||||||
|
/// # }
|
||||||
|
/// #
|
||||||
/// # impl FromStr for Timestamp {
|
/// # impl FromStr for Timestamp {
|
||||||
/// # type Err = String;
|
/// # type Err = String;
|
||||||
/// # fn from_str(_: &str) -> Result<Self, Self::Err> {
|
/// # fn from_str(_: &str) -> Result<Self, Self::Err> {
|
||||||
@@ -1040,7 +1044,7 @@ pub trait Deserializer<'de>: Sized {
|
|||||||
/// # fn seconds(_: u64) -> Self { unimplemented!() }
|
/// # fn seconds(_: u64) -> Self { unimplemented!() }
|
||||||
/// # }
|
/// # }
|
||||||
/// #
|
/// #
|
||||||
/// # impl Add<Duration> for () {
|
/// # impl Add<Duration> for Timestamp {
|
||||||
/// # type Output = Timestamp;
|
/// # type Output = Timestamp;
|
||||||
/// # fn add(self, _: Duration) -> Self::Output {
|
/// # fn add(self, _: Duration) -> Self::Output {
|
||||||
/// # unimplemented!()
|
/// # unimplemented!()
|
||||||
@@ -1058,8 +1062,6 @@ pub trait Deserializer<'de>: Sized {
|
|||||||
/// let s = String::deserialize(deserializer)?;
|
/// let s = String::deserialize(deserializer)?;
|
||||||
/// Timestamp::from_str(&s).map_err(de::Error::custom)
|
/// Timestamp::from_str(&s).map_err(de::Error::custom)
|
||||||
/// } else {
|
/// } else {
|
||||||
/// # // Make it look like an associated constant but compile on older rustc.
|
|
||||||
/// # mod Timestamp { pub const EPOCH: () = (); }
|
|
||||||
/// // Deserialize from a compact binary representation, seconds since
|
/// // Deserialize from a compact binary representation, seconds since
|
||||||
/// // the Unix epoch.
|
/// // the Unix epoch.
|
||||||
/// let n = u64::deserialize(deserializer)?;
|
/// let n = u64::deserialize(deserializer)?;
|
||||||
|
|||||||
+3
-1
@@ -79,7 +79,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.16")]
|
#![doc(html_root_url = "https://docs.rs/serde/1.0.17")]
|
||||||
|
|
||||||
// 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)]
|
||||||
@@ -207,6 +207,8 @@ mod lib {
|
|||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
pub use std::io::Write;
|
pub use std::io::Write;
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
|
pub use std::num::Wrapping;
|
||||||
|
#[cfg(feature = "std")]
|
||||||
pub use std::path::{Path, PathBuf};
|
pub use std::path::{Path, PathBuf};
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
pub use std::time::{Duration, SystemTime, UNIX_EPOCH};
|
pub use std::time::{Duration, SystemTime, UNIX_EPOCH};
|
||||||
|
|||||||
@@ -664,3 +664,19 @@ impl Serialize for OsString {
|
|||||||
self.as_os_str().serialize(serializer)
|
self.as_os_str().serialize(serializer)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#[cfg(feature = "std")]
|
||||||
|
impl<T> Serialize for Wrapping<T>
|
||||||
|
where
|
||||||
|
T: Serialize,
|
||||||
|
{
|
||||||
|
#[inline]
|
||||||
|
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||||
|
where
|
||||||
|
S: Serializer,
|
||||||
|
{
|
||||||
|
self.0.serialize(serializer)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "serde_derive"
|
name = "serde_derive"
|
||||||
version = "1.0.16" # remember to update html_root_url
|
version = "1.0.17" # remember to update html_root_url
|
||||||
authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>", "David Tolnay <dtolnay@gmail.com>"]
|
authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>", "David Tolnay <dtolnay@gmail.com>"]
|
||||||
license = "MIT/Apache-2.0"
|
license = "MIT/Apache-2.0"
|
||||||
description = "Macros 1.1 implementation of #[derive(Serialize, Deserialize)]"
|
description = "Macros 1.1 implementation of #[derive(Serialize, Deserialize)]"
|
||||||
@@ -22,3 +22,6 @@ proc-macro = true
|
|||||||
quote = "0.3.8"
|
quote = "0.3.8"
|
||||||
serde_derive_internals = { version = "=0.16.0", default-features = false, path = "../serde_derive_internals" }
|
serde_derive_internals = { version = "=0.16.0", default-features = false, path = "../serde_derive_internals" }
|
||||||
syn = { version = "0.11", features = ["visit"] }
|
syn = { version = "0.11", features = ["visit"] }
|
||||||
|
|
||||||
|
[dev-dependencies]
|
||||||
|
serde = { version = "1.0", path = "../serde" }
|
||||||
|
|||||||
@@ -8,15 +8,21 @@
|
|||||||
|
|
||||||
//! This crate provides Serde's two derive macros.
|
//! This crate provides Serde's two derive macros.
|
||||||
//!
|
//!
|
||||||
//! ```rust,ignore
|
//! ```rust
|
||||||
|
//! # #[macro_use]
|
||||||
|
//! # extern crate serde_derive;
|
||||||
|
//! #
|
||||||
//! #[derive(Serialize, Deserialize)]
|
//! #[derive(Serialize, Deserialize)]
|
||||||
|
//! # struct S;
|
||||||
|
//! #
|
||||||
|
//! # fn main() {}
|
||||||
//! ```
|
//! ```
|
||||||
//!
|
//!
|
||||||
//! Please refer to [https://serde.rs/derive.html] for how to set this up.
|
//! Please refer to [https://serde.rs/derive.html] for how to set this up.
|
||||||
//!
|
//!
|
||||||
//! [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.16")]
|
#![doc(html_root_url = "https://docs.rs/serde_derive/1.0.17")]
|
||||||
|
|
||||||
#![cfg_attr(feature = "cargo-clippy", allow(too_many_arguments))]
|
#![cfg_attr(feature = "cargo-clippy", allow(too_many_arguments))]
|
||||||
#![cfg_attr(feature = "cargo-clippy", allow(used_underscore_binding))]
|
#![cfg_attr(feature = "cargo-clippy", allow(used_underscore_binding))]
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "serde_test"
|
name = "serde_test"
|
||||||
version = "1.0.16" # remember to update html_root_url
|
version = "1.0.17" # remember to update html_root_url
|
||||||
authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>", "David Tolnay <dtolnay@gmail.com>"]
|
authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>", "David Tolnay <dtolnay@gmail.com>"]
|
||||||
license = "MIT/Apache-2.0"
|
license = "MIT/Apache-2.0"
|
||||||
description = "Token De/Serializer for testing De/Serialize implementations"
|
description = "Token De/Serializer for testing De/Serialize implementations"
|
||||||
|
|||||||
@@ -155,7 +155,7 @@
|
|||||||
//! # }
|
//! # }
|
||||||
//! ```
|
//! ```
|
||||||
|
|
||||||
#![doc(html_root_url = "https://docs.rs/serde_test/1.0.16")]
|
#![doc(html_root_url = "https://docs.rs/serde_test/1.0.17")]
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate serde;
|
extern crate serde;
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
// Copyright 2017 Serde Developers
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||||
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||||
|
// option. This file may not be copied, modified, or distributed
|
||||||
|
// except according to those terms.
|
||||||
|
|
||||||
|
#![feature(/*=============================================]
|
||||||
|
#![=== Serde test suite requires a nightly compiler. ===]
|
||||||
|
#![====================================================*/)]
|
||||||
|
|||||||
@@ -1,3 +1,11 @@
|
|||||||
|
// Copyright 2017 Serde Developers
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||||
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||||
|
// option. This file may not be copied, modified, or distributed
|
||||||
|
// except according to those terms.
|
||||||
|
|
||||||
#![feature(lang_items, start, compiler_builtins_lib)]
|
#![feature(lang_items, start, compiler_builtins_lib)]
|
||||||
#![no_std]
|
#![no_std]
|
||||||
|
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ mod remote {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)] //~ ERROR: missing field `b` in initializer of `remote::S`
|
#[derive(Serialize, Deserialize)]
|
||||||
#[serde(remote = "remote::S")]
|
#[serde(remote = "remote::S")]
|
||||||
struct S {
|
struct S {
|
||||||
a: u8, //~^^^ ERROR: missing field `b` in initializer of `remote::S`
|
a: u8, //~^^^ ERROR: missing field `b` in initializer of `remote::S`
|
||||||
|
|||||||
@@ -19,8 +19,7 @@ mod remote {
|
|||||||
#[serde(remote = "remote::S")]
|
#[serde(remote = "remote::S")]
|
||||||
struct S {
|
struct S {
|
||||||
//~^^^ ERROR: struct `remote::S` has no field named `b`
|
//~^^^ ERROR: struct `remote::S` has no field named `b`
|
||||||
//~^^^^ ERROR: struct `remote::S` has no field named `b`
|
b: u8, //~^^^^ ERROR: no field `b` on type `&remote::S`
|
||||||
b: u8, //~^^^^^ ERROR: no field `b` on type `&remote::S`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {}
|
fn main() {}
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ use std::default::Default;
|
|||||||
use std::ffi::{CString, OsString};
|
use std::ffi::{CString, OsString};
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
use std::num::Wrapping;
|
||||||
|
|
||||||
#[cfg(feature = "unstable")]
|
#[cfg(feature = "unstable")]
|
||||||
use std::ffi::CStr;
|
use std::ffi::CStr;
|
||||||
@@ -762,6 +763,14 @@ declare_tests! {
|
|||||||
Token::Bool(true),
|
Token::Bool(true),
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
|
test_wrapping {
|
||||||
|
Wrapping(1usize) => &[
|
||||||
|
Token::U32(1),
|
||||||
|
],
|
||||||
|
Wrapping(1usize) => &[
|
||||||
|
Token::U64(1),
|
||||||
|
],
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
declare_tests! {
|
declare_tests! {
|
||||||
@@ -1169,4 +1178,10 @@ declare_error_tests! {
|
|||||||
],
|
],
|
||||||
"invalid type: sequence, expected unit struct UnitStruct",
|
"invalid type: sequence, expected unit struct UnitStruct",
|
||||||
}
|
}
|
||||||
|
test_wrapping_overflow<Wrapping<u16>> {
|
||||||
|
&[
|
||||||
|
Token::U32(65536),
|
||||||
|
],
|
||||||
|
"invalid value: integer `65536`, expected u16",
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,11 @@
|
|||||||
|
// Copyright 2017 Serde Developers
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||||
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||||
|
// option. This file may not be copied, modified, or distributed
|
||||||
|
// except according to those terms.
|
||||||
|
|
||||||
extern crate serde_test;
|
extern crate serde_test;
|
||||||
use self::serde_test::{Token, assert_tokens_readable};
|
use self::serde_test::{Token, assert_tokens_readable};
|
||||||
|
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ use std::time::{Duration, UNIX_EPOCH};
|
|||||||
use std::ffi::CString;
|
use std::ffi::CString;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
use std::num::Wrapping;
|
||||||
|
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
use std::str;
|
use std::str;
|
||||||
@@ -399,6 +400,11 @@ declare_tests! {
|
|||||||
Token::Bool(true),
|
Token::Bool(true),
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
|
test_wrapping {
|
||||||
|
Wrapping(1usize) => &[
|
||||||
|
Token::U64(1),
|
||||||
|
],
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
declare_tests! {
|
declare_tests! {
|
||||||
|
|||||||
Reference in New Issue
Block a user