Skip to content

Commit

Permalink
Bump versions to release v2.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
jonasbb committed Jul 17, 2022
1 parent 8ad35a0 commit 427b025
Show file tree
Hide file tree
Showing 7 changed files with 123 additions and 32 deletions.
16 changes: 8 additions & 8 deletions README.md
Expand Up @@ -34,7 +34,7 @@ Add this to your `Cargo.toml`:

```toml
[dependencies.serde_with]
version = "2.0.0-rc.0"
version = "2.0.0"
features = [ "..." ]
```

Expand Down Expand Up @@ -158,14 +158,14 @@ Foo {
}
```

[`DisplayFromStr`]: https://docs.rs/serde_with/2.0.0-rc.0/serde_with/struct.DisplayFromStr.html
[`with_prefix!`]: https://docs.rs/serde_with/2.0.0-rc.0/serde_with/macro.with_prefix.html
[feature flags]: https://docs.rs/serde_with/2.0.0-rc.0/serde_with/guide/feature_flags/index.html
[skip_serializing_none]: https://docs.rs/serde_with/2.0.0-rc.0/serde_with/attr.skip_serializing_none.html
[StringWithSeparator]: https://docs.rs/serde_with/2.0.0-rc.0/serde_with/struct.StringWithSeparator.html
[user guide]: https://docs.rs/serde_with/2.0.0-rc.0/serde_with/guide/index.html
[`DisplayFromStr`]: https://docs.rs/serde_with/2.0.0/serde_with/struct.DisplayFromStr.html
[`with_prefix!`]: https://docs.rs/serde_with/2.0.0/serde_with/macro.with_prefix.html
[feature flags]: https://docs.rs/serde_with/2.0.0/serde_with/guide/feature_flags/index.html
[skip_serializing_none]: https://docs.rs/serde_with/2.0.0/serde_with/attr.skip_serializing_none.html
[StringWithSeparator]: https://docs.rs/serde_with/2.0.0/serde_with/struct.StringWithSeparator.html
[user guide]: https://docs.rs/serde_with/2.0.0/serde_with/guide/index.html
[with-annotation]: https://serde.rs/field-attrs.html#with
[as-annotation]: https://docs.rs/serde_with/2.0.0-rc.0/serde_with/guide/serde_as/index.html
[as-annotation]: https://docs.rs/serde_with/2.0.0/serde_with/guide/serde_as/index.html

## License

Expand Down
66 changes: 66 additions & 0 deletions serde_with/CHANGELOG.md
Expand Up @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

## [2.0.0] - 2022-07-17

### Added

* Make `JsonString<T>` smarter by allowing nesting `serde_as` definitions.
Expand All @@ -21,6 +23,68 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
{"value":"[[\"[1,2]\",3],[\"[4,5]\",6]]"}
```

### Changed

* Make `#[serde_as]` behave more intuitive on `Option<T>` fields.

The `#[serde_as]` macro now detects if a `#[serde_as(as = "Option<S>")]` is used on a field of type `Option<T>` and applies `#[serde(default)]` to the field.
This restores the ability to deserialize with missing fields and fixes a common annoyance (#183, #185, #311, #417).
This is a breaking change, since now deserialization will pass where it did not before and this might be undesired.

The `Option` field and transformation are detected by directly matching on the type name.
These variants are detected as `Option`.
* `Option`
* `std::option::Option`, with or without leading `::`
* `core::option::Option`, with or without leading `::`

If an existing `default` attribute is detected, the attribute is not applied again.
This behavior can be suppressed by using `#[serde_as(no_default)]` or `#[serde_as(as = "Option<S>", no_default)]`.
* `NoneAsEmptyString` and `string_empty_as_none` use a different serialization bound (#388).

Both types used `AsRef<str>` as the serialization bound.
This is limiting for non-string types like `Option<i32>`.
The deserialization often was already more flexible, due to the `FromStr` bound.

For most std types this should have little impact, as the types implementing `AsRef<str>` mostly implement `Display`, too, such as `String`, `Cow<str>`, or `Rc<str>`.
* Bump MSRV to 1.60. This is required for the optional dependency feature syntax in cargo.

### Removed

* Remove old module based conversions.

The newer `serde_as` based conversions are preferred.

* `seq_display_fromstr`: Use `DisplayFromStr` in combination with your container type:

```rust
#[serde_as(as = "BTreeSet<DisplayFromStr>")]
addresses: BTreeSet<Ipv4Addr>,
#[serde_as(as = "Vec<DisplayFromStr>")]
bools: Vec<bool>,
```

* `tuple_list_as_map`: Use `BTreeMap` on a `Vec` of tuples:

```rust
#[serde_as(as = "BTreeMap<_, _>")] // HashMap will also work
s: Vec<(i32, String)>,
```

* `map_as_tuple_list` can be replaced with `#[serde_as(as = "Vec<(_, _)>")]`.
* `display_fromstr` can be replaced with `#[serde_as(as = "DisplayFromStr")]`.
* `bytes_or_string` can be replaced with `#[serde_as(as = "BytesOrString")]`.
* `default_on_error` can be replaced with `#[serde_as(as = "DefaultOnError")]`.
* `default_on_null` can be replaced with `#[serde_as(as = "DefaultOnNull")]`.
* `string_empty_as_none` can be replaced with `#[serde_as(as = "NoneAsEmptyString")]`.
* `StringWithSeparator` can now only be used in `serde_as`.
The definition of the `Separator` trait and its implementations have been moved to the `formats` module.
* `json::nested` can be replaced with `#[serde_as(as = "json::JsonString")]`.

* Remove previously deprecated modules.

* `sets_first_value_wins`
* `btreemap_as_tuple_list` and `hashmap_as_tuple_list` can be replaced with `#[serde_as(as = "Vec<(_, _)>")]`.

## [2.0.0-rc.0] - 2022-06-29

### Changed
Expand Down Expand Up @@ -62,12 +126,14 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
#[serde_as(as = "Vec<DisplayFromStr>")]
bools: Vec<bool>,
```

* `tuple_list_as_map`: Use `BTreeMap` on a `Vec` of tuples:

```rust
#[serde_as(as = "BTreeMap<_, _>")] // HashMap will also work
s: Vec<(i32, String)>,
```

* `map_as_tuple_list` can be replaced with `#[serde_as(as = "Vec<(_, _)>")]`.
* `display_fromstr` can be replaced with `#[serde_as(as = "DisplayFromStr")]`.
* `bytes_or_string` can be replaced with `#[serde_as(as = "BytesOrString")]`.
Expand Down
4 changes: 2 additions & 2 deletions serde_with/Cargo.toml
Expand Up @@ -6,7 +6,7 @@ authors = [
]
name = "serde_with"
rust-version = "1.60"
version = "2.0.0-rc.0"
version = "2.0.0"

categories = ["encoding", "no-std"]
description = "Custom de/serialization functions for Rust's serde"
Expand Down Expand Up @@ -67,7 +67,7 @@ hex = {version = "0.4.3", optional = true, default-features = false}
indexmap_1 = {package = "indexmap", version = "1.8", optional = true, default-features = false, features = ["serde-1"]}
serde = {version = "1.0.122", default-features = false, features = ["derive"]}
serde_json = {version = "1.0.45", optional = true, default-features = false}
serde_with_macros = {path = "../serde_with_macros", version = "=2.0.0-rc.0", optional = true}
serde_with_macros = {path = "../serde_with_macros", version = "2.0.0", optional = true}
time_0_3 = {package = "time", version = "~0.3", optional = true, default-features = false}

[dev-dependencies]
Expand Down
30 changes: 15 additions & 15 deletions serde_with/src/lib.rs
@@ -1,8 +1,8 @@
#![warn(
clippy::semicolon_if_nothing_returned,
missing_crate_level_docs,
missing_docs,
rust_2018_idioms,
rustdoc::missing_crate_level_docs,
trivial_casts,
trivial_numeric_casts,
unused_extern_crates,
Expand All @@ -22,7 +22,7 @@
#![doc(test(attr(warn(rust_2018_idioms))))]
// Not needed for 2018 edition and conflicts with `rust_2018_idioms`
#![doc(test(no_crate_inject))]
#![doc(html_root_url = "https://docs.rs/serde_with/2.0.0-rc.0")]
#![doc(html_root_url = "https://docs.rs/serde_with/2.0.0")]
#![cfg_attr(docsrs, feature(doc_cfg))]
#![allow(
// clippy is broken and shows wrong warnings
Expand Down Expand Up @@ -71,7 +71,7 @@
//!
//! ```toml
//! [dependencies.serde_with]
//! version = "2.0.0-rc.0"
//! version = "2.0.0"
//! features = [ "..." ]
//! ```
//!
Expand Down Expand Up @@ -250,14 +250,14 @@
//! # }
//! ```
//!
//! [`DisplayFromStr`]: https://docs.rs/serde_with/2.0.0-rc.0/serde_with/struct.DisplayFromStr.html
//! [`with_prefix!`]: https://docs.rs/serde_with/2.0.0-rc.0/serde_with/macro.with_prefix.html
//! [feature flags]: https://docs.rs/serde_with/2.0.0-rc.0/serde_with/guide/feature_flags/index.html
//! [skip_serializing_none]: https://docs.rs/serde_with/2.0.0-rc.0/serde_with/attr.skip_serializing_none.html
//! [StringWithSeparator]: https://docs.rs/serde_with/2.0.0-rc.0/serde_with/struct.StringWithSeparator.html
//! [user guide]: https://docs.rs/serde_with/2.0.0-rc.0/serde_with/guide/index.html
//! [`DisplayFromStr`]: https://docs.rs/serde_with/2.0.0/serde_with/struct.DisplayFromStr.html
//! [`with_prefix!`]: https://docs.rs/serde_with/2.0.0/serde_with/macro.with_prefix.html
//! [feature flags]: https://docs.rs/serde_with/2.0.0/serde_with/guide/feature_flags/index.html
//! [skip_serializing_none]: https://docs.rs/serde_with/2.0.0/serde_with/attr.skip_serializing_none.html
//! [StringWithSeparator]: https://docs.rs/serde_with/2.0.0/serde_with/struct.StringWithSeparator.html
//! [user guide]: https://docs.rs/serde_with/2.0.0/serde_with/guide/index.html
//! [with-annotation]: https://serde.rs/field-attrs.html#with
//! [as-annotation]: https://docs.rs/serde_with/2.0.0-rc.0/serde_with/guide/serde_as/index.html
//! [as-annotation]: https://docs.rs/serde_with/2.0.0/serde_with/guide/serde_as/index.html

#[cfg(feature = "alloc")]
extern crate alloc;
Expand Down Expand Up @@ -398,7 +398,7 @@ pub use serde_with_macros::*;
/// # }
/// ```
///
/// [serde_as]: https://docs.rs/serde_with/2.0.0-rc.0/serde_with/attr.serde_as.html
/// [serde_as]: https://docs.rs/serde_with/2.0.0/serde_with/attr.serde_as.html
pub struct As<T: ?Sized>(PhantomData<T>);

impl<T: ?Sized> As<T> {
Expand Down Expand Up @@ -855,7 +855,7 @@ pub struct BytesOrString;
/// ```
///
/// [`chrono::Duration`]: ::chrono_0_4::Duration
/// [feature flag]: https://docs.rs/serde_with/2.0.0-rc.0/serde_with/guide/feature_flags/index.html
/// [feature flag]: https://docs.rs/serde_with/2.0.0/serde_with/guide/feature_flags/index.html
pub struct DurationSeconds<
FORMAT: formats::Format = u64,
STRICTNESS: formats::Strictness = formats::Strict,
Expand Down Expand Up @@ -983,7 +983,7 @@ pub struct DurationSeconds<
/// ```
///
/// [`chrono::Duration`]: ::chrono_0_4::Duration
/// [feature flag]: https://docs.rs/serde_with/2.0.0-rc.0/serde_with/guide/feature_flags/index.html
/// [feature flag]: https://docs.rs/serde_with/2.0.0/serde_with/guide/feature_flags/index.html
pub struct DurationSecondsWithFrac<
FORMAT: formats::Format = f64,
STRICTNESS: formats::Strictness = formats::Strict,
Expand Down Expand Up @@ -1179,7 +1179,7 @@ pub struct DurationNanoSecondsWithFrac<
/// [`SystemTime`]: std::time::SystemTime
/// [`chrono::DateTime<Local>`]: ::chrono_0_4::DateTime
/// [`chrono::DateTime<Utc>`]: ::chrono_0_4::DateTime
/// [feature flag]: https://docs.rs/serde_with/2.0.0-rc.0/serde_with/guide/feature_flags/index.html
/// [feature flag]: https://docs.rs/serde_with/2.0.0/serde_with/guide/feature_flags/index.html
pub struct TimestampSeconds<
FORMAT: formats::Format = i64,
STRICTNESS: formats::Strictness = formats::Strict,
Expand Down Expand Up @@ -1317,7 +1317,7 @@ pub struct TimestampSeconds<
/// [`chrono::DateTime<Local>`]: ::chrono_0_4::DateTime
/// [`chrono::DateTime<Utc>`]: ::chrono_0_4::DateTime
/// [NaiveDateTime]: ::chrono_0_4::NaiveDateTime
/// [feature flag]: https://docs.rs/serde_with/2.0.0-rc.0/serde_with/guide/feature_flags/index.html
/// [feature flag]: https://docs.rs/serde_with/2.0.0/serde_with/guide/feature_flags/index.html
pub struct TimestampSecondsWithFrac<
FORMAT: formats::Format = f64,
STRICTNESS: formats::Strictness = formats::Strict,
Expand Down
25 changes: 25 additions & 0 deletions serde_with_macros/CHANGELOG.md
Expand Up @@ -7,6 +7,31 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

## [2.0.0] - 2022-07-17

No changes compared to v2.0.0-rc.0.

### Changed

* Make `#[serde_as]` behave more intuitive on `Option<T>` fields.

The `#[serde_as]` macro now detects if a `#[serde_as(as = "Option<S>")]` is used on a field of type `Option<T>` and applies `#[serde(default)]` to the field.
This restores the ability to deserialize with missing fields and fixes a common annoyance (#183, #185, #311, #417).
This is a breaking change, since now deserialization will pass where it did not before and this might be undesired.

The `Option` field and transformation are detected by directly matching on the type name.
These variants are detected as `Option`.
* `Option`
* `std::option::Option`, with or without leading `::`
* `core::option::Option`, with or without leading `::`

If an existing `default` attribute is detected, the attribute is not applied again.
This behavior can be supressed by using `#[serde_as(no_default)]` or `#[serde_as(as = "Option<S>", no_default)]`.

### Fixed

* Make the documentation clearer by stating that the `#[serde_as]` and `#[skip_serializing_none]` attributes must always be placed before `#[derive]`.

## [2.0.0-rc.0] - 2022-06-29

### Changed
Expand Down
2 changes: 1 addition & 1 deletion serde_with_macros/Cargo.toml
Expand Up @@ -2,7 +2,7 @@
authors = ["Jonas Bushart"]
name = "serde_with_macros"
rust-version = "1.60"
version = "2.0.0-rc.0"
version = "2.0.0"

categories = ["encoding"]
description = "proc-macro library for serde_with"
Expand Down
12 changes: 6 additions & 6 deletions serde_with_macros/src/lib.rs
Expand Up @@ -2,10 +2,10 @@
#![warn(
clippy::semicolon_if_nothing_returned,
missing_copy_implementations,
missing_crate_level_docs,
missing_debug_implementations,
missing_docs,
rust_2018_idioms,
rustdoc::missing_crate_level_docs,
trivial_casts,
trivial_numeric_casts,
unused_extern_crates,
Expand All @@ -26,7 +26,7 @@
#![doc(test(attr(warn(rust_2018_idioms))))]
// Not needed for 2018 edition and conflicts with `rust_2018_idioms`
#![doc(test(no_crate_inject))]
#![doc(html_root_url = "https://docs.rs/serde_with_macros/2.0.0-rc.0")]
#![doc(html_root_url = "https://docs.rs/serde_with_macros/2.0.0")]
// Necessary to silence the warning about clippy::unknown_clippy_lints on nightly
#![allow(renamed_and_removed_lints)]
// Necessary for nightly clippy lints
Expand Down Expand Up @@ -526,8 +526,8 @@ fn field_has_attribute(field: &Field, namespace: &str, name: &str) -> bool {
/// }
/// ```
///
/// [`serde_as`]: https://docs.rs/serde_with/2.0.0-rc.0/serde_with/guide/index.html
/// [re-exporting `serde_as`]: https://docs.rs/serde_with/2.0.0-rc.0/serde_with/guide/serde_as/index.html#re-exporting-serde_as
/// [`serde_as`]: https://docs.rs/serde_with/2.0.0/serde_with/guide/index.html
/// [re-exporting `serde_as`]: https://docs.rs/serde_with/2.0.0/serde_with/guide/serde_as/index.html#re-exporting-serde_as
#[proc_macro_attribute]
pub fn serde_as(args: TokenStream, input: TokenStream) -> TokenStream {
#[derive(FromMeta)]
Expand Down Expand Up @@ -915,7 +915,7 @@ fn has_type_embedded(type_: &Type, embedded_type: &syn::Ident) -> bool {
/// [`Display`]: std::fmt::Display
/// [`FromStr`]: std::str::FromStr
/// [cargo-toml-rename]: https://doc.rust-lang.org/cargo/reference/specifying-dependencies.html#renaming-dependencies-in-cargotoml
/// [serde-as-crate]: https://docs.rs/serde_with/2.0.0-rc.0/serde_with/guide/serde_as/index.html#re-exporting-serde_as
/// [serde-as-crate]: https://docs.rs/serde_with/2.0.0/serde_with/guide/serde_as/index.html#re-exporting-serde_as
/// [serde-crate]: https://serde.rs/container-attrs.html#crate
#[proc_macro_derive(DeserializeFromStr, attributes(serde_with))]
pub fn derive_deserialize_fromstr(item: TokenStream) -> TokenStream {
Expand Down Expand Up @@ -1027,7 +1027,7 @@ fn deserialize_fromstr(mut input: DeriveInput, serde_with_crate_path: Path) -> T
/// [`Display`]: std::fmt::Display
/// [`FromStr`]: std::str::FromStr
/// [cargo-toml-rename]: https://doc.rust-lang.org/cargo/reference/specifying-dependencies.html#renaming-dependencies-in-cargotoml
/// [serde-as-crate]: https://docs.rs/serde_with/2.0.0-rc.0/serde_with/guide/serde_as/index.html#re-exporting-serde_as
/// [serde-as-crate]: https://docs.rs/serde_with/2.0.0/serde_with/guide/serde_as/index.html#re-exporting-serde_as
/// [serde-crate]: https://serde.rs/container-attrs.html#crate
#[proc_macro_derive(SerializeDisplay, attributes(serde_with))]
pub fn derive_serialize_display(item: TokenStream) -> TokenStream {
Expand Down

0 comments on commit 427b025

Please sign in to comment.