From 4ad4a1b4e9088219b7877d64aa225e6d352298e2 Mon Sep 17 00:00:00 2001 From: Jonas Bushart Date: Sat, 13 Jul 2024 00:39:04 +0200 Subject: [PATCH 1/2] Fix dead code warning by correcting a typo --- serde_with/tests/serde_as/map_tuple_list.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/serde_with/tests/serde_as/map_tuple_list.rs b/serde_with/tests/serde_as/map_tuple_list.rs index c5f5e564..90cbfbb0 100644 --- a/serde_with/tests/serde_as/map_tuple_list.rs +++ b/serde_with/tests/serde_as/map_tuple_list.rs @@ -224,7 +224,7 @@ fn test_tuple_array_as_map() { #[derive(Debug, PartialEq, Serialize, Deserialize)] struct S0(#[serde_as(as = "Map<_, _>")] [(u8, u8); 1]); is_equal( - S1([(1, 2)]), + S0([(1, 2)]), expect![[r#" { "1": 2 From f5b2626307f7fb49275232a7f1925bfb5a200a37 Mon Sep 17 00:00:00 2001 From: Jonas Bushart Date: Sat, 13 Jul 2024 01:03:00 +0200 Subject: [PATCH 2/2] Fix dead code warnings in tests --- serde_with/src/guide/serde_as.md | 4 ++++ serde_with/src/lib.rs | 17 +++++------------ 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/serde_with/src/guide/serde_as.md b/serde_with/src/guide/serde_as.md index b96fe42a..46f56ea2 100644 --- a/serde_with/src/guide/serde_as.md +++ b/serde_with/src/guide/serde_as.md @@ -44,6 +44,7 @@ Combined, this looks like: use serde::{Deserialize, Serialize}; use serde_with::{serde_as, DisplayFromStr}; +# #[allow(dead_code)] #[serde_as] #[derive(Serialize, Deserialize)] struct A { @@ -60,6 +61,7 @@ For example, the `mime` field from above could be nested in one or more data str # use serde::{Deserialize, Serialize}; # use serde_with::{serde_as, DisplayFromStr}; # +# #[allow(dead_code)] #[serde_as] #[derive(Serialize, Deserialize)] struct A { @@ -76,6 +78,7 @@ This means the field can still be missing during deserialization and will be fil This "magic" can break in some cases. Then it becomes necessary to apply `#[serde(default)]` on the field in question. If the field is of type `Option` and the conversion type is of `Option`, the default attribute is automatically applied. These variants are detected as `Option`. + * `Option` * `std::option::Option`, with or without leading `::` * `core::option::Option`, with or without leading `::` @@ -87,6 +90,7 @@ For more information, you can inspect the documentation of the `serde_as` macro. # use serde::{Deserialize, Serialize}; # use serde_with::{serde_as, DisplayFromStr}; # +# #[allow(dead_code)] #[serde_as] #[derive(Serialize, Deserialize)] struct A { diff --git a/serde_with/src/lib.rs b/serde_with/src/lib.rs index 7b4ec975..70b5cd28 100644 --- a/serde_with/src/lib.rs +++ b/serde_with/src/lib.rs @@ -77,11 +77,9 @@ //! //! [![Rustexplorer](https://img.shields.io/badge/Try%20on-rustexplorer-lightgrey?logo=rust&logoColor=orange)](https://www.rustexplorer.com/b/py7ida) //! ```rust -//! # #[cfg(feature = "macros")] +//! # #[cfg(all(feature = "macros", feature = "json"))] { //! # use serde::{Deserialize, Serialize}; -//! # #[cfg(feature = "macros")] //! # use serde_with::{serde_as, DisplayFromStr}; -//! # #[cfg(feature = "macros")] //! #[serde_as] //! # #[derive(Debug, Eq, PartialEq)] //! #[derive(Deserialize, Serialize)] @@ -91,7 +89,6 @@ //! bar: u8, //! } //! -//! # #[cfg(all(feature = "macros", feature = "json"))] { //! // This will serialize //! # let foo = //! Foo {bar: 12} @@ -115,11 +112,9 @@ //! //! [![Rustexplorer](https://img.shields.io/badge/Try%20on-rustexplorer-lightgrey?logo=rust&logoColor=orange)](https://www.rustexplorer.com/b/um0xyi) //! ```rust -//! # #[cfg(feature = "macros")] +//! # #[cfg(all(feature = "macros", feature = "json"))] { //! # use serde::{Deserialize, Serialize}; -//! # #[cfg(feature = "macros")] //! # use serde_with::{serde_as, Bytes}; -//! # #[cfg(feature = "macros")] //! #[serde_as] //! # #[derive(Debug, Eq, PartialEq)] //! #[derive(Deserialize, Serialize)] @@ -137,7 +132,6 @@ //! bytes: [u8; M], //! } //! -//! # #[cfg(all(feature = "macros", feature = "json"))] { //! // This allows us to serialize a struct like this //! let arrays: Arrays<100, 128> = Arrays { //! constgeneric: [true; 100], @@ -157,11 +151,9 @@ //! //! [![Rustexplorer](https://img.shields.io/badge/Try%20on-rustexplorer-lightgrey?logo=rust&logoColor=orange)](https://www.rustexplorer.com/b/xr1tm0) //! ```rust -//! # #[cfg(feature = "macros")] +//! # #[cfg(all(feature = "macros", feature = "json"))] { //! # use serde::{Deserialize, Serialize}; -//! # #[cfg(feature = "macros")] //! # use serde_with::skip_serializing_none; -//! # #[cfg(feature = "macros")] //! #[skip_serializing_none] //! # #[derive(Debug, Eq, PartialEq)] //! #[derive(Deserialize, Serialize)] @@ -175,7 +167,6 @@ //! g: Option, //! } //! -//! # #[cfg(all(feature = "macros", feature = "json"))] { //! // This will serialize //! # let foo = //! Foo {a: None, b: None, c: None, d: Some(4), e: None, f: None, g: Some(7)} @@ -461,6 +452,7 @@ pub use serde_with_macros::*; /// # use serde::{Deserialize, Serialize}; /// # use serde_with::{As, DisplayFromStr}; /// # +/// # #[allow(dead_code)] /// #[derive(Deserialize, Serialize)] /// # struct S { /// // Serialize numbers as sequence of strings, using Display and FromStr @@ -478,6 +470,7 @@ pub use serde_with_macros::*; /// # use serde_with::{As, DisplayFromStr, Same}; /// # use std::collections::BTreeMap; /// # +/// # #[allow(dead_code)] /// #[derive(Deserialize, Serialize)] /// # struct S { /// // Serialize map, turn keys into strings but keep type of value