Skip to content

Commit

Permalink
Fix dead code warning by correcting a typo (#769)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonasbb authored Jul 12, 2024
2 parents 1c4b022 + f5b2626 commit 31e9172
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 13 deletions.
4 changes: 4 additions & 0 deletions serde_with/src/guide/serde_as.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand All @@ -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<T>` and the conversion type is of `Option<S>`, 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 `::`
Expand All @@ -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 {
Expand Down
17 changes: 5 additions & 12 deletions serde_with/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand All @@ -91,7 +89,6 @@
//! bar: u8,
//! }
//!
//! # #[cfg(all(feature = "macros", feature = "json"))] {
//! // This will serialize
//! # let foo =
//! Foo {bar: 12}
Expand All @@ -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)]
Expand All @@ -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],
Expand All @@ -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)]
Expand All @@ -175,7 +167,6 @@
//! g: Option<usize>,
//! }
//!
//! # #[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)}
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion serde_with/tests/serde_as/map_tuple_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 31e9172

Please sign in to comment.