Compare commits

...

5 Commits

Author SHA1 Message Date
David Tolnay 7aeabddd2f Release 1.0.27 2017-12-30 22:19:41 -05:00
David Tolnay 9df8f5ecc0 Merge pull request #1132 from Lireer/uppercase
Add UPPERCASE to rename_all
2017-12-30 22:18:20 -05:00
Carl Scherer c4fad2883b Add UPPERCASE to rename_all 2017-12-31 03:12:00 +01:00
David Tolnay 9cfcd78c87 Release 1.0.26 2017-12-27 17:33:32 -05:00
David Tolnay 4751627f1c Implement De/Serialize for PhantomData where T: ?Sized 2017-12-27 17:32:49 -05:00
11 changed files with 30 additions and 19 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
[package] [package]
name = "serde" name = "serde"
version = "1.0.25" # remember to update html_root_url version = "1.0.27" # 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"
+3 -3
View File
@@ -548,11 +548,11 @@ where
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
struct PhantomDataVisitor<T> { struct PhantomDataVisitor<T: ?Sized> {
marker: PhantomData<T>, marker: PhantomData<T>,
} }
impl<'de, T> Visitor<'de> for PhantomDataVisitor<T> { impl<'de, T: ?Sized> Visitor<'de> for PhantomDataVisitor<T> {
type Value = PhantomData<T>; type Value = PhantomData<T>;
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result { fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
@@ -568,7 +568,7 @@ impl<'de, T> Visitor<'de> for PhantomDataVisitor<T> {
} }
} }
impl<'de, T> Deserialize<'de> for PhantomData<T> { impl<'de, T: ?Sized> Deserialize<'de> for PhantomData<T> {
fn deserialize<D>(deserializer: D) -> Result<PhantomData<T>, D::Error> fn deserialize<D>(deserializer: D) -> Result<PhantomData<T>, D::Error>
where where
D: Deserializer<'de>, D: Deserializer<'de>,
+1 -1
View File
@@ -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.25")] #![doc(html_root_url = "https://docs.rs/serde/1.0.27")]
// 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
+1 -1
View File
@@ -111,7 +111,7 @@ where
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
impl<T> Serialize for PhantomData<T> { impl<T: ?Sized> Serialize for PhantomData<T> {
#[inline] #[inline]
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where where
+2 -2
View File
@@ -1,6 +1,6 @@
[package] [package]
name = "serde_derive" name = "serde_derive"
version = "1.0.25" # remember to update html_root_url version = "1.0.27" # 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)]"
@@ -24,7 +24,7 @@ proc-macro = true
[dependencies] [dependencies]
quote = "0.3.8" quote = "0.3.8"
serde_derive_internals = { version = "=0.18.1", default-features = false, path = "../serde_derive_internals" } serde_derive_internals = { version = "=0.19.0", default-features = false, path = "../serde_derive_internals" }
syn = { version = "0.11", features = ["visit"] } syn = { version = "0.11", features = ["visit"] }
[dev-dependencies] [dev-dependencies]
+1 -1
View File
@@ -22,7 +22,7 @@
//! //!
//! [https://serde.rs/derive.html]: https://serde.rs/derive.html //! [https://serde.rs/derive.html]: https://serde.rs/derive.html
#![doc(html_root_url = "https://docs.rs/serde_derive/1.0.25")] #![doc(html_root_url = "https://docs.rs/serde_derive/1.0.27")]
#![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))]
// The `quote!` macro requires deep recursion. // The `quote!` macro requires deep recursion.
+1 -1
View File
@@ -1,6 +1,6 @@
[package] [package]
name = "serde_derive_internals" name = "serde_derive_internals"
version = "0.18.1" # remember to update html_root_url version = "0.19.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>"]
license = "MIT/Apache-2.0" license = "MIT/Apache-2.0"
description = "AST representation used by Serde derive macros. Unstable." description = "AST representation used by Serde derive macros. Unstable."
+17 -6
View File
@@ -20,6 +20,8 @@ pub enum RenameRule {
None, None,
/// Rename direct children to "lowercase" style. /// Rename direct children to "lowercase" style.
LowerCase, LowerCase,
/// Rename direct children to "UPPERCASE" style.
UPPERCASE,
/// Rename direct children to "PascalCase" style, as typically used for enum variants. /// Rename direct children to "PascalCase" style, as typically used for enum variants.
PascalCase, PascalCase,
/// Rename direct children to "camelCase" style. /// Rename direct children to "camelCase" style.
@@ -39,6 +41,7 @@ impl RenameRule {
match *self { match *self {
None | PascalCase => variant.to_owned(), None | PascalCase => variant.to_owned(),
LowerCase => variant.to_ascii_lowercase(), LowerCase => variant.to_ascii_lowercase(),
UPPERCASE => variant.to_ascii_uppercase(),
CamelCase => variant[..1].to_ascii_lowercase() + &variant[1..], CamelCase => variant[..1].to_ascii_lowercase() + &variant[1..],
SnakeCase => { SnakeCase => {
let mut snake = String::new(); let mut snake = String::new();
@@ -61,6 +64,7 @@ impl RenameRule {
pub fn apply_to_field(&self, field: &str) -> String { pub fn apply_to_field(&self, field: &str) -> String {
match *self { match *self {
None | LowerCase | SnakeCase => field.to_owned(), None | LowerCase | SnakeCase => field.to_owned(),
UPPERCASE => field.to_ascii_uppercase(),
PascalCase => { PascalCase => {
let mut pascal = String::new(); let mut pascal = String::new();
let mut capitalize = true; let mut capitalize = true;
@@ -93,6 +97,7 @@ impl FromStr for RenameRule {
fn from_str(rename_all_str: &str) -> Result<Self, Self::Err> { fn from_str(rename_all_str: &str) -> Result<Self, Self::Err> {
match rename_all_str { match rename_all_str {
"lowercase" => Ok(LowerCase), "lowercase" => Ok(LowerCase),
"UPPERCASE" => Ok(UPPERCASE),
"PascalCase" => Ok(PascalCase), "PascalCase" => Ok(PascalCase),
"camelCase" => Ok(CamelCase), "camelCase" => Ok(CamelCase),
"snake_case" => Ok(SnakeCase), "snake_case" => Ok(SnakeCase),
@@ -106,10 +111,11 @@ impl FromStr for RenameRule {
#[test] #[test]
fn rename_variants() { fn rename_variants() {
for &(original, lower, camel, snake, screaming, kebab, screaming_kebab) in &[ for &(original, lower, upper, camel, snake, screaming, kebab, screaming_kebab) in &[
( (
"Outcome", "Outcome",
"outcome", "outcome",
"OUTCOME",
"outcome", "outcome",
"outcome", "outcome",
"OUTCOME", "OUTCOME",
@@ -119,17 +125,19 @@ fn rename_variants() {
( (
"VeryTasty", "VeryTasty",
"verytasty", "verytasty",
"VERYTASTY",
"veryTasty", "veryTasty",
"very_tasty", "very_tasty",
"VERY_TASTY", "VERY_TASTY",
"very-tasty", "very-tasty",
"VERY-TASTY", "VERY-TASTY",
), ),
("A", "a", "a", "a", "A", "a", "A"), ("A", "a", "A", "a", "a", "A", "a", "A"),
("Z42", "z42", "z42", "z42", "Z42", "z42", "Z42"), ("Z42", "z42", "Z42", "z42", "z42", "Z42", "z42", "Z42"),
] { ] {
assert_eq!(None.apply_to_variant(original), original); assert_eq!(None.apply_to_variant(original), original);
assert_eq!(LowerCase.apply_to_variant(original), lower); assert_eq!(LowerCase.apply_to_variant(original), lower);
assert_eq!(UPPERCASE.apply_to_variant(original), upper);
assert_eq!(PascalCase.apply_to_variant(original), original); assert_eq!(PascalCase.apply_to_variant(original), original);
assert_eq!(CamelCase.apply_to_variant(original), camel); assert_eq!(CamelCase.apply_to_variant(original), camel);
assert_eq!(SnakeCase.apply_to_variant(original), snake); assert_eq!(SnakeCase.apply_to_variant(original), snake);
@@ -144,9 +152,10 @@ fn rename_variants() {
#[test] #[test]
fn rename_fields() { fn rename_fields() {
for &(original, pascal, camel, screaming, kebab, screaming_kebab) in &[ for &(original, upper, pascal, camel, screaming, kebab, screaming_kebab) in &[
( (
"outcome", "outcome",
"OUTCOME",
"Outcome", "Outcome",
"outcome", "outcome",
"OUTCOME", "OUTCOME",
@@ -155,16 +164,18 @@ fn rename_fields() {
), ),
( (
"very_tasty", "very_tasty",
"VERY_TASTY",
"VeryTasty", "VeryTasty",
"veryTasty", "veryTasty",
"VERY_TASTY", "VERY_TASTY",
"very-tasty", "very-tasty",
"VERY-TASTY", "VERY-TASTY",
), ),
("a", "A", "a", "A", "a", "A"), ("a", "A", "A", "a", "A", "a", "A"),
("z42", "Z42", "z42", "Z42", "z42", "Z42"), ("z42", "Z42", "Z42", "z42", "Z42", "z42", "Z42"),
] { ] {
assert_eq!(None.apply_to_field(original), original); assert_eq!(None.apply_to_field(original), original);
assert_eq!(UPPERCASE.apply_to_field(original), upper);
assert_eq!(PascalCase.apply_to_field(original), pascal); assert_eq!(PascalCase.apply_to_field(original), pascal);
assert_eq!(CamelCase.apply_to_field(original), camel); assert_eq!(CamelCase.apply_to_field(original), camel);
assert_eq!(SnakeCase.apply_to_field(original), original); assert_eq!(SnakeCase.apply_to_field(original), original);
+1 -1
View File
@@ -6,7 +6,7 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
#![doc(html_root_url = "https://docs.rs/serde_derive_internals/0.18.1")] #![doc(html_root_url = "https://docs.rs/serde_derive_internals/0.19.0")]
extern crate syn; extern crate syn;
#[macro_use] #[macro_use]
+1 -1
View File
@@ -1,6 +1,6 @@
[package] [package]
name = "serde_test" name = "serde_test"
version = "1.0.25" # remember to update html_root_url version = "1.0.27" # 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"
+1 -1
View File
@@ -155,7 +155,7 @@
//! # } //! # }
//! ``` //! ```
#![doc(html_root_url = "https://docs.rs/serde_test/1.0.25")] #![doc(html_root_url = "https://docs.rs/serde_test/1.0.27")]
#![cfg_attr(feature = "cargo-clippy", deny(clippy, clippy_pedantic))] #![cfg_attr(feature = "cargo-clippy", deny(clippy, clippy_pedantic))]
// Whitelisted clippy lints // Whitelisted clippy lints
#![cfg_attr(feature = "cargo-clippy", allow(float_cmp))] #![cfg_attr(feature = "cargo-clippy", allow(float_cmp))]