From 580557086d1991a56412e854e48eea15ec765477 Mon Sep 17 00:00:00 2001 From: Ritvik Nag Date: Sat, 25 Jan 2025 00:03:29 -0500 Subject: [PATCH] Add release notes for `v0.5.0` --- CHANGELOG.md | 43 ++++++++++++++++++++++++++++++++++++++----- Cargo.toml | 26 +++++++++++++------------- README.md | 28 ++++++++++++++++++++-------- src/lib.rs | 2 +- 4 files changed, 72 insertions(+), 27 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8e13fe7..59730b6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ Possible header types: - `Breaking Changes` for any backwards-incompatible changes. ## [Unreleased] + +## v0.5.0 (2025-01-25) + +### Features + +- **Added support for optional deserialization**: + - New functions were introduced to handle `Option` types during deserialization: + - `as_opt_bool` – Returns `Option`. + - `as_opt_f64` – Returns `Option`. + - `as_opt_i64` – Returns `Option`. + - `as_opt_string` – Returns `Option`. + - `as_opt_u64` – Returns `Option`. + + These functions ensure that `null` values in the JSON input or deserialization errors are correctly deserialized into + `None`, + while valid values will + return the appropriate `Some(T)`. + +### Bug Fixes + +- Resolved an issue where the existing deserialization functions did not handle `Option` types, only direct types. + Now, + `null` values and errors are deserialized to `None`, making the handling of nulls more consistent with Serde's + standard + behavior. + +### Breaking Changes + +- No breaking changes introduced in this version. + ## v0.4.2 (2023-02-05) ### Bug Fixes @@ -32,24 +62,27 @@ Possible header types: ## v0.4.0 (2022-04-18) ### Features + - Add benchmarks to compare performance against `serde_with`. - Flatten some nested `match` arms into simpler `if` statements. - Update `as_bool` - - Update to check for a new "truthy" string value of `ON`. - - Add pattern matching to check common *true/false* values **before** converting the string - to uppercase, which should make it overall more efficient. + - Update to check for a new "truthy" string value of `ON`. + - Add pattern matching to check common *true/false* values **before** converting the string + to uppercase, which should make it overall more efficient. - `serde_this_or_that` is now on par - in terms of performance - with `serde_with`! This is truly great news. ## v0.3.0 (2022-04-17) ### Breaking Changes + - Remove dependency on the `derive` feature of `serde` - - Add it as an optional feature named `derive` instead. + - Add it as an optional feature named `derive` instead. ### Features + - Replace `utilities` keyword with `this-or-that`, as I want crate to be - searchable when someone types "this or that". + searchable when someone types "this or that". - Update docs. ## v0.2.0 (2022-04-17) diff --git a/Cargo.toml b/Cargo.toml index d5fa9d8..642da3d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,23 +1,23 @@ [package] name = "serde-this-or-that" -version = "0.4.2" -authors = ["Ritvik Nag "] +version = "0.5.0" +authors = ["Ritvik Nag "] description = "Custom deserialization for fields that can be specified as multiple types." documentation = "https://docs.rs/serde-this-or-that" repository = "https://github.com/rnag/serde-this-or-that" readme = "README.md" keywords = ["serde", - # I would have liked to add the below keyword, but of course - # crates.io has a limit of 5 keywords, so well.. that's that. :\ - # "utilities", - # And now surprisingly, I found this keyword to be super useful! - # I'm actually partially shocked that crates.io doesn't use the - # crate name to automagically satisfy user search requests. - "this-or-that", - # Of course, the rest that follow are also pretty solid too. - "deserialization", - "visitor", - "multiple-type"] + # I would have liked to add the below keyword, but of course + # crates.io has a limit of 5 keywords, so well.. that's that. :\ + # "utilities", + # And now surprisingly, I found this keyword to be super useful! + # I'm actually partially shocked that crates.io doesn't use the + # crate name to automagically satisfy user search requests. + "this-or-that", + # Of course, the rest that follow are also pretty solid too. + "deserialization", + "visitor", + "multiple-type"] categories = ["encoding"] license = "MIT" edition = "2021" diff --git a/README.md b/README.md index 629a283..0083634 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ This crate works with Cargo with a `Cargo.toml` like: ```toml [dependencies] -serde-this-or-that = "0.4" +serde-this-or-that = "0.5" serde = { version = "1", features = ["derive"] } serde_json = "1" ``` @@ -67,15 +67,21 @@ fn main() -> Result<(), Box> { ## Exported Functions -- [`as_bool`](https://docs.rs/serde-this-or-that/latest/serde_this_or_that/fn.as_bool.html) / [`as_opt_bool`](https://docs.rs/serde-this-or-that/latest/serde_this_or_that/fn.as_opt_bool.html) -- [`as_f64`](https://docs.rs/serde-this-or-that/latest/serde_this_or_that/fn.as_f64.html) / [`as_opt_f64`](https://docs.rs/serde-this-or-that/latest/serde_this_or_that/fn.as_opt_f64.html) -- [`as_i64`](https://docs.rs/serde-this-or-that/latest/serde_this_or_that/fn.as_i64.html) / [`as_opt_i64`](https://docs.rs/serde-this-or-that/latest/serde_this_or_that/fn.as_opt_i64.html) -- [`as_string`](https://docs.rs/serde-this-or-that/latest/serde_this_or_that/fn.as_string.html) / [`as_opt_string`](https://docs.rs/serde-this-or-that/latest/serde_this_or_that/fn.as_opt_string.html) -- [`as_u64`](https://docs.rs/serde-this-or-that/latest/serde_this_or_that/fn.as_u64.html) / [`as_opt_u64`](https://docs.rs/serde-this-or-that/latest/serde_this_or_that/fn.as_opt_u64.html) +- [`as_bool`](https://docs.rs/serde-this-or-that/latest/serde_this_or_that/fn.as_bool.html) / [ + `as_opt_bool`](https://docs.rs/serde-this-or-that/latest/serde_this_or_that/fn.as_opt_bool.html) +- [`as_f64`](https://docs.rs/serde-this-or-that/latest/serde_this_or_that/fn.as_f64.html) / [ + `as_opt_f64`](https://docs.rs/serde-this-or-that/latest/serde_this_or_that/fn.as_opt_f64.html) +- [`as_i64`](https://docs.rs/serde-this-or-that/latest/serde_this_or_that/fn.as_i64.html) / [ + `as_opt_i64`](https://docs.rs/serde-this-or-that/latest/serde_this_or_that/fn.as_opt_i64.html) +- [`as_string`](https://docs.rs/serde-this-or-that/latest/serde_this_or_that/fn.as_string.html) / [ + `as_opt_string`](https://docs.rs/serde-this-or-that/latest/serde_this_or_that/fn.as_opt_string.html) +- [`as_u64`](https://docs.rs/serde-this-or-that/latest/serde_this_or_that/fn.as_u64.html) / [ + `as_opt_u64`](https://docs.rs/serde-this-or-that/latest/serde_this_or_that/fn.as_opt_u64.html) ## Examples -You can check out sample usage of this crate in the [examples/](https://github.com/rnag/serde-this-or-that/tree/main/examples) +You can check out sample usage of this crate in +the [examples/](https://github.com/rnag/serde-this-or-that/tree/main/examples) folder in the project repo on GitHub. ## Performance @@ -94,9 +100,13 @@ The benchmarks live in the [benches/](https://github.com/rnag/serde-this-or-that folder, and can be run with `cargo bench`. [`Visitor`]: https://docs.serde.rs/serde/de/trait.Visitor.html + [untagged enum]: https://stackoverflow.com/a/66961340/10237506 + [serde_with]: https://docs.rs/serde_with + [`DisplayFromStr`]: https://docs.rs/serde_with/latest/serde_with/struct.DisplayFromStr.html + [`PickFirst`]: https://docs.rs/serde_with/latest/serde_with/struct.PickFirst.html ## Optionals @@ -104,7 +114,8 @@ folder, and can be run with `cargo bench`. The extra helper functions that begin with `as_opt`, return an `Option` of the respective data type `T`, rather than the type `T` itself (see [#4](https://github.com/rnag/serde-this-or-that/issues/4)). -On success, they return a value of `T` wrapped in [`Some`](https://doc.rust-lang.org/std/option/enum.Option.html#variant.Some). +On success, they return a value of `T` wrapped in [ +`Some`](https://doc.rust-lang.org/std/option/enum.Option.html#variant.Some). On error, or when there is a `null` value, or one of an *invalid* data type, the `as_opt` helper functions return [`None`](https://doc.rust-lang.org/std/option/enum.Option.html#variant.None) instead. @@ -117,6 +128,7 @@ to discuss a new feature or change. Check out the [Contributing][] section in the docs for more info. [Contributing]: CONTRIBUTING.md + [open an issue]: https://github.com/rnag/serde-this-or-that/issues ## License diff --git a/src/lib.rs b/src/lib.rs index 24e1321..6dc6c5d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,4 +1,4 @@ -#![doc(html_root_url = "https://docs.rs/serde-this-or-that/0.4.2")] +#![doc(html_root_url = "https://docs.rs/serde-this-or-that/0.5.0")] #![warn(rust_2018_idioms, missing_docs)] #![deny(warnings, dead_code, unused_imports, unused_mut)]