Compare commits

...

13 Commits

Author SHA1 Message Date
David Tolnay c8e3959435 Release 1.0.86 2019-02-01 21:07:19 -08:00
David Tolnay 796f412a1e Document that Bound<T> impls exist 2019-02-01 21:07:18 -08:00
David Tolnay fa854a2108 Format with rustfmt 2018-12-10 2019-02-01 21:04:08 -08:00
David Tolnay 3a097ff2d2 Deserialize Bound::Unbounded as unit variant 2019-02-01 21:04:07 -08:00
David Tolnay 8463bfc1e5 Remove as yet unrequested range impls 2019-02-01 21:04:06 -08:00
David Tolnay 7a72b4c624 Merge pull request #1466 from 0nkery/master
Impl Serialize/Deserialize for std::ops::{Bound, RangeFrom, RangeTo, RangeToInclusive}
2019-02-01 21:03:55 -08:00
David Tolnay 670c179417 Re-enable deny unused_imports 2019-02-01 17:56:52 -08:00
David Tolnay 1b1d868837 Combine the two clippy lists 2019-02-01 17:56:31 -08:00
David Tolnay d9704d02bb Remove clippy lints that are no longer triggering 2019-02-01 17:53:14 -08:00
David Tolnay 1349548367 Fix indentation of cfg that isn't formatted by rustfmt 2019-02-01 17:48:14 -08:00
Dmitry Shlagoff 18b1604fc8 Fix compatibility issues with syntax and Bound 2019-01-30 00:41:03 +07:00
Dmitry Shlagoff 0def7da5a8 Impl Ser/De for RangeFrom, RangeTo, RangeToInclusive 2019-01-29 20:29:14 +07:00
Dmitry Shlagoff 4bb45c8252 Impl Serialize for Bound<T> 2019-01-29 15:20:27 +07:00
16 changed files with 256 additions and 70 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
[package]
name = "serde"
version = "1.0.85" # remember to update html_root_url
version = "1.0.86" # remember to update html_root_url
authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>", "David Tolnay <dtolnay@gmail.com>"]
license = "MIT/Apache-2.0"
description = "A generic serialization/deserialization framework"
+9
View File
@@ -14,6 +14,15 @@ fn main() {
let target = env::var("TARGET").unwrap();
let emscripten = target == "asmjs-unknown-emscripten" || target == "wasm32-unknown-emscripten";
// std::collections::Bound was stabilized in Rust 1.17
// but it was moved to core::ops later in Rust 1.26:
// https://doc.rust-lang.org/core/ops/enum.Bound.html
if minor >= 26 {
println!("cargo:rustc-cfg=ops_bound");
} else if minor >= 17 && cfg!(feature = "std") {
println!("cargo:rustc-cfg=collections_bound");
}
// CString::into_boxed_c_str stabilized in Rust 1.20:
// https://doc.rust-lang.org/std/ffi/struct.CString.html#method.into_boxed_c_str
if minor >= 20 {
+111
View File
@@ -2269,6 +2269,117 @@ mod range {
////////////////////////////////////////////////////////////////////////////////
#[cfg(any(ops_bound, collections_bound))]
impl<'de, T> Deserialize<'de> for Bound<T>
where
T: Deserialize<'de>,
{
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: Deserializer<'de>,
{
enum Field {
Unbounded,
Included,
Excluded,
}
impl<'de> Deserialize<'de> for Field {
#[inline]
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: Deserializer<'de>,
{
struct FieldVisitor;
impl<'de> Visitor<'de> for FieldVisitor {
type Value = Field;
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
formatter.write_str("`Unbounded`, `Included` or `Excluded`")
}
fn visit_u32<E>(self, value: u32) -> Result<Self::Value, E>
where
E: Error,
{
match value {
0 => Ok(Field::Unbounded),
1 => Ok(Field::Included),
2 => Ok(Field::Excluded),
_ => Err(Error::invalid_value(
Unexpected::Unsigned(value as u64),
&self,
)),
}
}
fn visit_str<E>(self, value: &str) -> Result<Self::Value, E>
where
E: Error,
{
match value {
"Unbounded" => Ok(Field::Unbounded),
"Included" => Ok(Field::Included),
"Excluded" => Ok(Field::Excluded),
_ => Err(Error::unknown_variant(value, VARIANTS)),
}
}
fn visit_bytes<E>(self, value: &[u8]) -> Result<Self::Value, E>
where
E: Error,
{
match value {
b"Unbounded" => Ok(Field::Unbounded),
b"Included" => Ok(Field::Included),
b"Excluded" => Ok(Field::Excluded),
_ => match str::from_utf8(value) {
Ok(value) => Err(Error::unknown_variant(value, VARIANTS)),
Err(_) => {
Err(Error::invalid_value(Unexpected::Bytes(value), &self))
}
},
}
}
}
deserializer.deserialize_identifier(FieldVisitor)
}
}
struct BoundVisitor<T>(PhantomData<Bound<T>>);
impl<'de, T> Visitor<'de> for BoundVisitor<T>
where
T: Deserialize<'de>,
{
type Value = Bound<T>;
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
formatter.write_str("enum Bound")
}
fn visit_enum<A>(self, data: A) -> Result<Self::Value, A::Error>
where
A: EnumAccess<'de>,
{
match try!(data.variant()) {
(Field::Unbounded, v) => v.unit_variant().map(|()| Bound::Unbounded),
(Field::Included, v) => v.newtype_variant().map(Bound::Included),
(Field::Excluded, v) => v.newtype_variant().map(Bound::Excluded),
}
}
}
const VARIANTS: &'static [&'static str] = &["Unbounded", "Included", "Excluded"];
deserializer.deserialize_enum("Bound", VARIANTS, BoundVisitor(PhantomData))
}
}
////////////////////////////////////////////////////////////////////////////////
macro_rules! nonzero_integers {
( $( $T: ident, )+ ) => {
$(
+1
View File
@@ -89,6 +89,7 @@
//! - PathBuf
//! - Range\<T\>
//! - RangeInclusive\<T\>
//! - Bound\<T\>
//! - num::NonZero*
//! - `!` *(unstable)*
//! - **Net types**:
+28 -39
View File
@@ -75,7 +75,7 @@
////////////////////////////////////////////////////////////////////////////////
// Serde types in rustdoc of other crates get linked to here.
#![doc(html_root_url = "https://docs.rs/serde/1.0.85")]
#![doc(html_root_url = "https://docs.rs/serde/1.0.86")]
// Support using Serde without the standard library!
#![cfg_attr(not(feature = "std"), no_std)]
// Unstable functionality only if the user asks for it. For tracking and
@@ -86,52 +86,35 @@
#![cfg_attr(feature = "alloc", feature(alloc))]
#![cfg_attr(feature = "cargo-clippy", allow(renamed_and_removed_lints))]
#![cfg_attr(feature = "cargo-clippy", deny(clippy, clippy_pedantic))]
// Ignored clippy lints
// Ignored clippy and clippy_pedantic lints
#![cfg_attr(
feature = "cargo-clippy",
allow(
cast_lossless,
// not available in our oldest supported compiler
const_static_lifetime,
doc_markdown,
linkedlist,
needless_pass_by_value,
empty_enum,
redundant_field_names,
// integer and float ser/de requires these sorts of casts
cast_possible_truncation,
cast_possible_wrap,
cast_precision_loss,
cast_sign_loss,
// things are often more readable this way
cast_lossless,
module_name_repetitions,
single_match_else,
type_complexity,
unreadable_literal,
zero_prefixed_literal
use_self,
zero_prefixed_literal,
// not practical
needless_pass_by_value,
similar_names,
// preference
doc_markdown,
)
)]
// Ignored clippy_pedantic lints
#![cfg_attr(feature = "cargo-clippy", allow(
// integer and float ser/de requires these sorts of casts
cast_possible_truncation,
cast_possible_wrap,
cast_precision_loss,
cast_sign_loss,
// simplifies some macros
invalid_upcast_comparisons,
// things are often more readable this way
decimal_literal_representation,
module_name_repetitions,
option_unwrap_used,
result_unwrap_used,
shadow_reuse,
single_match_else,
use_self,
// not practical
indexing_slicing,
many_single_char_names,
missing_docs_in_private_items,
similar_names,
// alternative is not stable
empty_enum,
use_debug,
))]
// Blacklisted Rust lints.
//
// Compiler bug involving unused_imports:
// https://github.com/rust-lang/rust/issues/51661
#![deny(missing_docs, /*unused_imports*/)]
// Rustc lints.
#![deny(missing_docs, unused_imports)]
////////////////////////////////////////////////////////////////////////////////
@@ -224,6 +207,12 @@ mod lib {
#[cfg(range_inclusive)]
pub use self::core::ops::RangeInclusive;
#[cfg(all(feature = "std", collections_bound))]
pub use std::collections::Bound;
#[cfg(ops_bound)]
pub use self::core::ops::Bound;
}
////////////////////////////////////////////////////////////////////////////////
+23
View File
@@ -256,6 +256,29 @@ where
////////////////////////////////////////////////////////////////////////////////
#[cfg(any(ops_bound, collections_bound))]
impl<T> Serialize for Bound<T>
where
T: Serialize,
{
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
match *self {
Bound::Unbounded => serializer.serialize_unit_variant("Bound", 0, "Unbounded"),
Bound::Included(ref value) => {
serializer.serialize_newtype_variant("Bound", 1, "Included", value)
}
Bound::Excluded(ref value) => {
serializer.serialize_newtype_variant("Bound", 2, "Excluded", value)
}
}
}
}
////////////////////////////////////////////////////////////////////////////////
impl Serialize for () {
#[inline]
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
+1
View File
@@ -84,6 +84,7 @@
//! - PathBuf
//! - Range\<T\>
//! - RangeInclusive\<T\>
//! - Bound\<T\>
//! - num::NonZero*
//! - `!` *(unstable)*
//! - **Net types**:
+1 -1
View File
@@ -1,6 +1,6 @@
[package]
name = "serde_derive"
version = "1.0.85" # remember to update html_root_url
version = "1.0.86" # remember to update html_root_url
authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>", "David Tolnay <dtolnay@gmail.com>"]
license = "MIT/Apache-2.0"
description = "Macros 1.1 implementation of #[derive(Serialize, Deserialize)]"
+20 -4
View File
@@ -1149,7 +1149,11 @@ fn prepare_enum_variant_enum(
.enumerate()
.filter(|&(_, variant)| !variant.attrs.skip_deserializing())
.map(|(i, variant)| {
(variant.attrs.name().deserialize_name(), field_i(i), variant.attrs.aliases())
(
variant.attrs.name().deserialize_name(),
field_i(i),
variant.attrs.aliases(),
)
})
.collect();
@@ -2275,7 +2279,11 @@ fn deserialize_struct_as_struct_visitor(
.enumerate()
.filter(|&(_, field)| !field.attrs.skip_deserializing())
.map(|(i, field)| {
(field.attrs.name().deserialize_name(), field_i(i), field.attrs.aliases())
(
field.attrs.name().deserialize_name(),
field_i(i),
field.attrs.aliases(),
)
})
.collect();
@@ -2304,7 +2312,11 @@ fn deserialize_struct_as_map_visitor(
.enumerate()
.filter(|&(_, field)| !field.attrs.skip_deserializing() && !field.attrs.flatten())
.map(|(i, field)| {
(field.attrs.name().deserialize_name(), field_i(i), field.attrs.aliases())
(
field.attrs.name().deserialize_name(),
field_i(i),
field.attrs.aliases(),
)
})
.collect();
@@ -2537,7 +2549,11 @@ fn deserialize_struct_as_struct_in_place_visitor(
.enumerate()
.filter(|&(_, field)| !field.attrs.skip_deserializing())
.map(|(i, field)| {
(field.attrs.name().deserialize_name(), field_i(i), field.attrs.aliases())
(
field.attrs.name().deserialize_name(),
field_i(i),
field.attrs.aliases(),
)
})
.collect();
+4 -2
View File
@@ -116,8 +116,10 @@ impl<'c, T> VecAttr<'c, T> {
fn at_most_one(mut self) -> Result<Option<T>, ()> {
if self.values.len() > 1 {
let dup_token = self.first_dup_tokens;
self.cx
.error_spanned_by(dup_token, format!("duplicate serde attribute `{}`", self.name));
self.cx.error_spanned_by(
dup_token,
format!("duplicate serde attribute `{}`", self.name),
);
Err(())
} else {
Ok(self.values.pop())
+1 -1
View File
@@ -13,7 +13,7 @@
//!
//! [https://serde.rs/derive.html]: https://serde.rs/derive.html
#![doc(html_root_url = "https://docs.rs/serde_derive/1.0.85")]
#![doc(html_root_url = "https://docs.rs/serde_derive/1.0.86")]
#![cfg_attr(feature = "cargo-clippy", allow(renamed_and_removed_lints))]
#![cfg_attr(feature = "cargo-clippy", deny(clippy, clippy_pedantic))]
// Ignored clippy lints
+1 -1
View File
@@ -1,6 +1,6 @@
[package]
name = "serde_test"
version = "1.0.85" # remember to update html_root_url
version = "1.0.86" # remember to update html_root_url
authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>", "David Tolnay <dtolnay@gmail.com>"]
license = "MIT/Apache-2.0"
description = "Token De/Serializer for testing De/Serialize implementations"
+1 -1
View File
@@ -144,7 +144,7 @@
//! # }
//! ```
#![doc(html_root_url = "https://docs.rs/serde_test/1.0.85")]
#![doc(html_root_url = "https://docs.rs/serde_test/1.0.86")]
#![cfg_attr(feature = "cargo-clippy", allow(renamed_and_removed_lints))]
#![cfg_attr(feature = "cargo-clippy", deny(clippy, clippy_pedantic))]
// Ignored clippy lints
+18 -20
View File
@@ -574,7 +574,11 @@ fn test_rename_struct() {
);
assert_de_tokens(
&AliasStruct { a1: 1, a2: 2, a4: 3 },
&AliasStruct {
a1: 1,
a2: 2,
a4: 3,
},
&[
Token::Struct {
name: "AliasStruct",
@@ -591,7 +595,11 @@ fn test_rename_struct() {
);
assert_de_tokens(
&AliasStruct { a1: 1, a2: 2, a4: 3 },
&AliasStruct {
a1: 1,
a2: 2,
a4: 3,
},
&[
Token::Struct {
name: "AliasStruct",
@@ -665,7 +673,7 @@ enum AliasEnum {
b: i8,
#[serde(alias = "e", rename = "f")]
d: i8,
}
},
}
#[test]
@@ -756,11 +764,7 @@ fn test_rename_enum() {
);
assert_de_tokens(
&AliasEnum::SailorMoon {
a: 0,
b: 1,
d: 2,
},
&AliasEnum::SailorMoon { a: 0, b: 1, d: 2 },
&[
Token::StructVariant {
name: "AliasEnum",
@@ -778,11 +782,7 @@ fn test_rename_enum() {
);
assert_de_tokens(
&AliasEnum::SailorMoon {
a: 0,
b: 1,
d: 2,
},
&AliasEnum::SailorMoon { a: 0, b: 1, d: 2 },
&[
Token::StructVariant {
name: "AliasEnum",
@@ -803,13 +803,11 @@ fn test_rename_enum() {
#[test]
fn test_unknown_field_rename_enum() {
assert_de_tokens_error::<AliasEnum>(
&[
Token::StructVariant {
name: "AliasEnum",
variant: "SailorMoon",
len: 3,
},
],
&[Token::StructVariant {
name: "AliasEnum",
variant: "SailorMoon",
len: 3,
}],
"unknown variant `SailorMoon`, expected `sailor_moon`",
);
+18
View File
@@ -6,6 +6,7 @@ use std::default::Default;
use std::ffi::{CStr, CString, OsString};
use std::net;
use std::num::Wrapping;
use std::ops::Bound;
use std::path::{Path, PathBuf};
use std::rc::{Rc, Weak as RcWeak};
use std::sync::{Arc, Weak as ArcWeak};
@@ -836,6 +837,23 @@ declare_tests! {
Token::SeqEnd,
],
}
test_bound {
Bound::Unbounded::<()> => &[
Token::Enum { name: "Bound" },
Token::Str("Unbounded"),
Token::Unit,
],
Bound::Included(0) => &[
Token::Enum { name: "Bound" },
Token::Str("Included"),
Token::U8(0),
],
Bound::Excluded(0) => &[
Token::Enum { name: "Bound" },
Token::Str("Excluded"),
Token::U8(0),
],
}
test_path {
Path::new("/usr/local/lib") => &[
Token::BorrowedStr("/usr/local/lib"),
+18
View File
@@ -6,6 +6,7 @@ use std::ffi::CString;
use std::mem;
use std::net;
use std::num::Wrapping;
use std::ops::Bound;
use std::path::{Path, PathBuf};
use std::rc::{Rc, Weak as RcWeak};
use std::sync::{Arc, Weak as ArcWeak};
@@ -375,6 +376,23 @@ declare_tests! {
Token::StructEnd,
],
}
test_bound {
Bound::Unbounded::<()> => &[
Token::Enum { name: "Bound" },
Token::Str("Unbounded"),
Token::Unit,
],
Bound::Included(0u8) => &[
Token::Enum { name: "Bound" },
Token::Str("Included"),
Token::U8(0),
],
Bound::Excluded(0u8) => &[
Token::Enum { name: "Bound" },
Token::Str("Excluded"),
Token::U8(0),
],
}
test_path {
Path::new("/usr/local/lib") => &[
Token::Str("/usr/local/lib"),