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