Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions serde_with/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
* Update `syn` and `darling` dependencies to use `syn` v3 (#992)
* Update dev-dependencies to newer versions (#993)
* Update `base64` to a newer version. This should not have any API change, but some error messages might change. (#993)
* `serde_as` can now parse `cfg_attr(true, ...)` and `cfg_attr(false, ...)` (#995)
`true`/`false` are new literals as of Rust 1.88 but need to be parsed explicitly with the `syn` types.
This is used when emitting `schemars` annotations.

## [3.22.0] - 2026-08-09

Expand Down
12 changes: 6 additions & 6 deletions serde_with/src/guide/serde_as.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ Our goal is to serialize this `Data` struct.
Currently, we do not have anything we can use to replace `???` with, since `_` only works if `RemoteType` would implement `Serialize`, which it does not.

```rust
# #[cfg(any())] {
# #[cfg(false)] {
#[serde_as]
#[derive(serde::Serialize)]
struct Data {
Expand All @@ -163,7 +163,7 @@ The `SerializeAs` implementation is **always** written for a local type.
This allows it to seamlessly work with types from dependencies without running into orphan rule problems.

```rust
# #[cfg(any())] {
# #[cfg(false)] {
struct LocalType;

impl SerializeAs<RemoteType> for LocalType {
Expand Down Expand Up @@ -192,7 +192,7 @@ As can be seen, this is mostly boilerplate, since the most part is encapsulated
The final `Data` struct will now look like:

```rust
# #[cfg(any())] {
# #[cfg(false)] {
#[serde_as]
#[derive(serde::Serialize)]
struct Data {
Expand All @@ -209,7 +209,7 @@ This is a special functionality of serde, where it derives the de/serialization
You can find all the details in the [official serde documentation](https://serde.rs/remote-derive.html).

```rust
# #[cfg(any())] {
# #[cfg(false)] {
// Pretend that this is somebody else's crate, not a module.
mod other_crate {
// Neither Serde nor the other crate provides Serialize and Deserialize
Expand Down Expand Up @@ -242,7 +242,7 @@ We can write this implementation.
The implementation for `DeserializeAs` works analogue.

```rust
# #[cfg(any())] {
# #[cfg(false)] {
impl SerializeAs<Duration> for DurationDef {
fn serialize_as<S>(value: &Duration, serializer: S) -> Result<S::Ok, S::Error>
where
Expand All @@ -257,7 +257,7 @@ impl SerializeAs<Duration> for DurationDef {
This now allows us to use `Duration` for serialization.

```rust
# #[cfg(any())] {
# #[cfg(false)] {
use other_crate::Duration;

#[serde_as]
Expand Down
8 changes: 4 additions & 4 deletions serde_with/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1857,7 +1857,7 @@ pub struct PickFirst<T>(PhantomData<T>);
/// Deserializing works analogue, by deserializing a `T` and then converting into `O`.
///
/// ```rust
/// # #[cfg(any())] {
/// # #[cfg(false)] {
/// struct S {
/// #[serde_as(as = "FromInto<T>")]
/// value: O,
Expand Down Expand Up @@ -1939,7 +1939,7 @@ pub struct FromInto<T>(PhantomData<T>);
/// Deserializing works analogue, by deserializing a `T` and then converting into `O`.
///
/// ```rust
/// # #[cfg(any())] {
/// # #[cfg(false)] {
/// struct S {
/// #[serde_as(as = "FromIntoRef<T>")]
/// value: O,
Expand Down Expand Up @@ -2020,7 +2020,7 @@ pub struct FromIntoRef<T>(PhantomData<T>);
/// Deserializing works analogue, by deserializing a `T` and then converting into `O`.
///
/// ```rust
/// # #[cfg(any())] {
/// # #[cfg(false)] {
/// struct S {
/// #[serde_as(as = "TryFromInto<T>")]
/// value: O,
Expand Down Expand Up @@ -2109,7 +2109,7 @@ pub struct TryFromInto<T>(PhantomData<T>);
/// Deserializing works analogue, by deserializing a `T` and then converting into `O`.
///
/// ```rust
/// # #[cfg(any())] {
/// # #[cfg(false)] {
/// struct S {
/// #[serde_as(as = "TryFromIntoRef<T>")]
/// value: O,
Expand Down
10 changes: 5 additions & 5 deletions serde_with/src/rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use crate::prelude::*;
/// This cannot work, since there is no way to tell the `Vec` to skip the inner `DoubleOption` if it is `None`.
///
/// ```rust
/// # #[cfg(any())] {
/// # #[cfg(false)] {
/// # struct Foobar {
/// #[serde_as(as = "Vec<DoubleOption<_>>")]
/// data: Vec<Option<Option<i32>>>,
Expand Down Expand Up @@ -182,7 +182,7 @@ pub mod unwrap_or_skip {
/// The `_` is a placeholder which works for any type which implements [`Serialize`]/[`Deserialize`].
///
/// ```rust
/// # #[cfg(any())] {
/// # #[cfg(false)] {
/// #[serde_as]
/// #[derive(Deserialize, Serialize)]
/// struct A {
Expand Down Expand Up @@ -298,7 +298,7 @@ pub mod sets_duplicate_value_is_error {
/// The `_` is a placeholder which works for any type which implements [`Serialize`]/[`Deserialize`].
///
/// ```rust
/// # #[cfg(any())] {
/// # #[cfg(false)] {
/// #[serde_as]
/// #[derive(Deserialize, Serialize)]
/// struct A {
Expand Down Expand Up @@ -418,7 +418,7 @@ pub mod maps_duplicate_key_is_error {
/// The `_` is a placeholder which works for any type which implements [`Serialize`]/[`Deserialize`].
///
/// ```rust
/// # #[cfg(any())] {
/// # #[cfg(false)] {
/// #[serde_as]
/// #[derive(Deserialize, Serialize)]
/// struct A {
Expand Down Expand Up @@ -506,7 +506,7 @@ pub mod sets_last_value_wins {
/// The `_` is a placeholder which works for any type which implements [`Serialize`]/[`Deserialize`].
///
/// ```rust
/// # #[cfg(any())] {
/// # #[cfg(false)] {
/// #[serde_as]
/// #[derive(Deserialize, Serialize)]
/// struct A {
Expand Down
16 changes: 8 additions & 8 deletions serde_with/tests/schemars_0_8/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ fn schemars_other_cfg_attrs() {
#[derive(JsonSchema, Serialize)]
struct Test {
#[serde_as(as = "DisplayFromStr")]
#[cfg_attr(any(), arbitrary("some" |weird| syntax::<bool, 2>()))]
#[cfg_attr(any(), schemars(with = "i32"))]
#[cfg_attr(false, arbitrary("some" |weird| syntax::<bool, 2>()))]
#[cfg_attr(false, schemars(with = "i32"))]
custom: i32,
}

Expand All @@ -152,11 +152,11 @@ fn schemars_custom_with() {
custom: i32,

#[serde_as(as = "DisplayFromStr")]
#[cfg_attr(any(), schemars(with = "i32"))]
#[cfg_attr(false, schemars(with = "i32"))]
with_disabled: i32,

#[serde_as(as = "DisplayFromStr")]
#[cfg_attr(all(), schemars(with = "i32"))]
#[cfg_attr(true, schemars(with = "i32"))]
always_enabled: i32,
}

Expand Down Expand Up @@ -226,11 +226,11 @@ fn schemars_custom_schema_with() {
custom: i32,

#[serde_as(as = "DisplayFromStr")]
#[cfg_attr(any(), schemars(schema_with = "custom_int"))]
#[cfg_attr(false, schemars(schema_with = "custom_int"))]
with_disabled: i32,

#[serde_as(as = "DisplayFromStr")]
#[cfg_attr(all(), schemars(schema_with = "custom_int"))]
#[cfg_attr(true, schemars(schema_with = "custom_int"))]
always_enabled: i32,
}

Expand Down Expand Up @@ -494,7 +494,7 @@ mod derive {

#[serde_as]
#[derive(Serialize)]
#[cfg_attr(all(), derive(JsonSchema))]
#[cfg_attr(true, derive(JsonSchema))]
struct Enabled {
#[serde_as(as = "DisplayFromStr")]
field: u32,
Expand All @@ -503,7 +503,7 @@ mod derive {
#[allow(dead_code)]
#[serde_as]
#[derive(Serialize)]
#[cfg_attr(any(), derive(JsonSchema))]
#[cfg_attr(false, derive(JsonSchema))]
struct Disabled {
// If we are incorrectly adding `#[schemars(with = ...)]` attributes
// then we should get an error on this field.
Expand Down
16 changes: 8 additions & 8 deletions serde_with/tests/schemars_0_9/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@ fn schemars_other_cfg_attrs() {
#[derive(JsonSchema, Serialize)]
struct Test {
#[serde_as(as = "DisplayFromStr")]
#[cfg_attr(any(), arbitrary("some" |weird| syntax::<bool, 2>()))]
#[cfg_attr(any(), schemars(with = "i32"))]
#[cfg_attr(false, arbitrary("some" |weird| syntax::<bool, 2>()))]
#[cfg_attr(false, schemars(with = "i32"))]
custom: i32,
}

Expand All @@ -153,11 +153,11 @@ fn schemars_custom_with() {
custom: i32,

#[serde_as(as = "DisplayFromStr")]
#[cfg_attr(any(), schemars(with = "i32"))]
#[cfg_attr(false, schemars(with = "i32"))]
with_disabled: i32,

#[serde_as(as = "DisplayFromStr")]
#[cfg_attr(all(), schemars(with = "i32"))]
#[cfg_attr(true, schemars(with = "i32"))]
always_enabled: i32,
}

Expand Down Expand Up @@ -225,11 +225,11 @@ fn schemars_custom_schema_with() {
custom: i32,

#[serde_as(as = "DisplayFromStr")]
#[cfg_attr(any(), schemars(schema_with = "custom_int"))]
#[cfg_attr(false, schemars(schema_with = "custom_int"))]
with_disabled: i32,

#[serde_as(as = "DisplayFromStr")]
#[cfg_attr(all(), schemars(schema_with = "custom_int"))]
#[cfg_attr(true, schemars(schema_with = "custom_int"))]
always_enabled: i32,
}

Expand Down Expand Up @@ -493,7 +493,7 @@ mod derive {

#[serde_as]
#[derive(Serialize)]
#[cfg_attr(all(), derive(JsonSchema))]
#[cfg_attr(true, derive(JsonSchema))]
struct Enabled {
#[serde_as(as = "DisplayFromStr")]
field: u32,
Expand All @@ -502,7 +502,7 @@ mod derive {
#[allow(dead_code)]
#[serde_as]
#[derive(Serialize)]
#[cfg_attr(any(), derive(JsonSchema))]
#[cfg_attr(false, derive(JsonSchema))]
struct Disabled {
// If we are incorrectly adding `#[schemars(with = ...)]` attributes
// then we should get an error on this field.
Expand Down
16 changes: 8 additions & 8 deletions serde_with/tests/schemars_1/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@ fn schemars_other_cfg_attrs() {
#[derive(JsonSchema, Serialize)]
struct Test {
#[serde_as(as = "DisplayFromStr")]
#[cfg_attr(any(), arbitrary("some" |weird| syntax::<bool, 2>()))]
#[cfg_attr(any(), schemars(with = "i32"))]
#[cfg_attr(false, arbitrary("some" |weird| syntax::<bool, 2>()))]
#[cfg_attr(false, schemars(with = "i32"))]
custom: i32,
}

Expand All @@ -153,11 +153,11 @@ fn schemars_custom_with() {
custom: i32,

#[serde_as(as = "DisplayFromStr")]
#[cfg_attr(any(), schemars(with = "i32"))]
#[cfg_attr(false, schemars(with = "i32"))]
with_disabled: i32,

#[serde_as(as = "DisplayFromStr")]
#[cfg_attr(all(), schemars(with = "i32"))]
#[cfg_attr(true, schemars(with = "i32"))]
always_enabled: i32,
}

Expand Down Expand Up @@ -217,11 +217,11 @@ fn schemars_custom_schema_with() {
custom: i32,

#[serde_as(as = "DisplayFromStr")]
#[cfg_attr(any(), schemars(schema_with = "custom_int"))]
#[cfg_attr(false, schemars(schema_with = "custom_int"))]
with_disabled: i32,

#[serde_as(as = "DisplayFromStr")]
#[cfg_attr(all(), schemars(schema_with = "custom_int"))]
#[cfg_attr(true, schemars(schema_with = "custom_int"))]
always_enabled: i32,
}

Expand Down Expand Up @@ -492,7 +492,7 @@ mod derive {

#[serde_as]
#[derive(Serialize)]
#[cfg_attr(all(), derive(JsonSchema))]
#[cfg_attr(true, derive(JsonSchema))]
struct Enabled {
#[serde_as(as = "DisplayFromStr")]
field: u32,
Expand All @@ -501,7 +501,7 @@ mod derive {
#[allow(dead_code)]
#[serde_as]
#[derive(Serialize)]
#[cfg_attr(any(), derive(JsonSchema))]
#[cfg_attr(false, derive(JsonSchema))]
struct Disabled {
// If we are incorrectly adding `#[schemars(with = ...)]` attributes
// then we should get an error on this field.
Expand Down
3 changes: 3 additions & 0 deletions serde_with_macros/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
### Changed

* Update `syn` and `darling` dependencies to use `syn` v3 (#992)
* `serde_as` can now parse `cfg_attr(true, ...)` and `cfg_attr(false, ...)` (#995)
`true`/`false` are new literals as of Rust 1.88 but need to be parsed explicitly with the `syn` types.
This is used when emitting `schemars` annotations.

## [3.22.0] - 2026-08-09

Expand Down
Loading