Skip to content

Commit

Permalink
Add Changelog and guide entry
Browse files Browse the repository at this point in the history
  • Loading branch information
jonasbb committed May 28, 2022
1 parent 34fbc97 commit 82bd5b8
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 21 deletions.
17 changes: 16 additions & 1 deletion serde_with/CHANGELOG.md
Expand Up @@ -24,7 +24,6 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

`time::OffsetDateTime` and `time::PrimitiveDateTime` can now be serialized with the `TimestampSeconds` and related converters.


```rust
// Rust
#[serde_as(as = "serde_with::TimestampMicroSecondsWithFrac<String>")]
Expand All @@ -49,6 +48,22 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
"rfc_3339": ["1997-11-21T09:55:06-06:00"],
```

* Deserialize `bool` from integers #456 462

Deserialize an integer and convert it into a `bool`.
`BoolFromInt<Strict>` (default) deserializes 0 to `false` and `1` to `true`, other numbers are errors.
`BoolFromInt<Flexible>` deserializes any non-zero as `true`.
Serialization only emits 0/1.

```rust
// Rust
#[serde_as(as = "BoolFromInt")] // BoolFromInt<Strict>
b: bool,

// JSON
"b": 1,
```

### Changed

* Bump MSRV to 1.53, since the new dependency `time` requires that version.
Expand Down
59 changes: 39 additions & 20 deletions serde_with/src/guide/serde_as_transformations.md
Expand Up @@ -4,26 +4,27 @@ This page lists the transformations implemented in this crate and supported by `

1. [Base64 encode bytes](#base64-encode-bytes)
2. [Big Array support](#big-array-support)
3. [Borrow from the input for `Cow` type](#borrow-from-the-input-for-cow-type)
4. [`Bytes` with more efficiency](#bytes-with-more-efficiency)
5. [Convert to an intermediate type using `Into`](#convert-to-an-intermediate-type-using-into)
6. [Convert to an intermediate type using `TryInto`](#convert-to-an-intermediate-type-using-tryinto)
7. [`Default` from `null`](#default-from-null)
8. [De/Serialize into `Vec`, ignoring errors](#deserialize-into-vec-ignoring-errors)
9. [De/Serialize with `FromStr` and `Display`](#deserialize-with-fromstr-and-display)
10. [`Duration` as seconds](#duration-as-seconds)
11. [Hex encode bytes](#hex-encode-bytes)
12. [Ignore deserialization errors](#ignore-deserialization-errors)
13. [`Maps` to `Vec` of enums](#maps-to-vec-of-enums)
14. [`Maps` to `Vec` of tuples](#maps-to-vec-of-tuples)
15. [`NaiveDateTime` like UTC timestamp](#naivedatetime-like-utc-timestamp)
16. [`None` as empty `String`](#none-as-empty-string)
17. [One or many elements into `Vec`](#one-or-many-elements-into-vec)
18. [Pick first successful deserialization](#pick-first-successful-deserialization)
19. [Timestamps as seconds since UNIX epoch](#timestamps-as-seconds-since-unix-epoch)
20. [Value into JSON String](#value-into-json-string)
21. [`Vec` of tuples to `Maps`](#vec-of-tuples-to-maps)
22. [Well-known time formats for `OffsetDateTime`](#well-known-time-formats-for-offsetdatetime)
3. [`bool` from integer](#bool-from-integer)
4. [Borrow from the input for `Cow` type](#borrow-from-the-input-for-cow-type)
5. [`Bytes` with more efficiency](#bytes-with-more-efficiency)
6. [Convert to an intermediate type using `Into`](#convert-to-an-intermediate-type-using-into)
7. [Convert to an intermediate type using `TryInto`](#convert-to-an-intermediate-type-using-tryinto)
8. [`Default` from `null`](#default-from-null)
9. [De/Serialize into `Vec`, ignoring errors](#deserialize-into-vec-ignoring-errors)
10. [De/Serialize with `FromStr` and `Display`](#deserialize-with-fromstr-and-display)
11. [`Duration` as seconds](#duration-as-seconds)
12. [Hex encode bytes](#hex-encode-bytes)
13. [Ignore deserialization errors](#ignore-deserialization-errors)
14. [`Maps` to `Vec` of enums](#maps-to-vec-of-enums)
15. [`Maps` to `Vec` of tuples](#maps-to-vec-of-tuples)
16. [`NaiveDateTime` like UTC timestamp](#naivedatetime-like-utc-timestamp)
17. [`None` as empty `String`](#none-as-empty-string)
18. [One or many elements into `Vec`](#one-or-many-elements-into-vec)
19. [Pick first successful deserialization](#pick-first-successful-deserialization)
20. [Timestamps as seconds since UNIX epoch](#timestamps-as-seconds-since-unix-epoch)
21. [Value into JSON String](#value-into-json-string)
22. [`Vec` of tuples to `Maps`](#vec-of-tuples-to-maps)
23. [Well-known time formats for `OffsetDateTime`](#well-known-time-formats-for-offsetdatetime)

## Base64 encode bytes

Expand Down Expand Up @@ -57,6 +58,22 @@ value: [[u8; 64]; 33],
"value": [[0,0,0,0,0,...], [0,0,0,...], ...],
```

## `bool` from integer

Deserialize an integer and convert it into a `bool`.
[`BoolFromInt<Strict>`] (default) deserializes 0 to `false` and `1` to `true`, other numbers are errors.
[`BoolFromInt<Flexible>`] deserializes any non-zero as `true`.
Serialization only emits 0/1.

```ignore
// Rust
#[serde_as(as = "BoolFromInt")] // BoolFromInt<Strict>
b: bool,
// JSON
"b": 1,
```

## Borrow from the input for `Cow` type

The types `Cow<'_, str>`, `Cow<'_, [u8]>`, or `Cow<'_, [u8; N]>` can borrow from the input, avoiding extra copies.
Expand Down Expand Up @@ -471,6 +488,8 @@ rfc_3339: OffsetDateTime,
These conversions are availble with the `time_0_3` feature flag.

[`Base64`]: crate::base64::Base64
[`BoolFromInt<Flexible>`]: crate::BoolFromInt
[`BoolFromInt<Strict>`]: crate::BoolFromInt
[`Bytes`]: crate::Bytes
[`chrono::DateTime<Local>`]: chrono_crate::DateTime
[`chrono::DateTime<Utc>`]: chrono_crate::DateTime
Expand Down

0 comments on commit 82bd5b8

Please sign in to comment.