Skip to content

Commit

Permalink
Add documentation and changelog for the new feature
Browse files Browse the repository at this point in the history
  • Loading branch information
jonasbb committed Mar 7, 2021
1 parent 83b09b6 commit b3441a7
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 11 deletions.
45 changes: 45 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,51 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## Unreleased

### Added

* Add support for arrays of arbitrary size.
This feature requires Rust 1.51+.

```rust
// Rust
#[serde_as(as = "[[_; 64]; 33]")]
value: [[u8; 64]; 33],

// JSON
"value": [[0,0,0,0,0,...], [0,0,0,...], ...],
```

Mapping of arrays was available before, but limited to arrays of length 32.
All conversion methods are available for the array elements.

This is similar to the existing [`serde-big-array`] crate with three important improvements:

1. Support for the `serde_as` annotation.
2. Supports non-copy elements (see [serde-big-array#6][serde-big-array-copy]).
3. Supports arbitrary nestings of arrays (see [serde-big-array#7][serde-big-array-nested]).

[`serde-big-array`]: https://crates.io/crates/serde-big-array
[serde-big-array-copy]: https://github.com/est31/serde-big-array/issues/6
[serde-big-array-nested]: https://github.com/est31/serde-big-array/issues/7

* Arrays with tuple elements can now be deserialized from a map.
This feature requires Rust 1.51+.

```rust
// Rust
#[serde_as(as = "BTreeMap<_, _>")]
value: [(String, u16); 3],

// JSON
"value": {
"a": 1,
"b": 2,
"c": 3
},
```

## [1.6.4]

### Fixed
Expand Down
39 changes: 28 additions & 11 deletions src/guide/serde_as.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,18 @@ The basic design of the system was done by [@markazmierczak](https://github.com/
4. [Using `#[serde_as]` with serde's remote derives](#using-serde_as-with-serdes-remote-derives)
5. [Re-exporting `serde_as`](#re-exporting-serde_as)
2. [De/Serialize Implementations Available](#deserialize-implementations-available)
1. [Bytes / `Vec<u8>` to hex string](#bytes--vecu8-to-hex-string)
2. [`Default` from `null`](#default-from-null)
3. [De/Serialize with `FromStr` and `Display`](#deserialize-with-fromstr-and-display)
4. [`Duration` as seconds](#duration-as-seconds)
5. [Ignore deserialization errors](#ignore-deserialization-errors)
6. [`Maps` to `Vec` of tuples](#maps-to-vec-of-tuples)
7. [`NaiveDateTime` like UTC timestamp](#naivedatetime-like-utc-timestamp)
8. [`None` as empty `String`](#none-as-empty-string)
9. [Timestamps as seconds since UNIX epoch](#timestamps-as-seconds-since-unix-epoch)
10. [Value into JSON String](#value-into-json-string)
11. [`Vec` of tuples to `Maps`](#vec-of-tuples-to-maps)
1. [Big Array support (Rust 1.51+)](#big-array-support-rust-151)
2. [Bytes / `Vec<u8>` to hex string](#bytes--vecu8-to-hex-string)
3. [`Default` from `null`](#default-from-null)
4. [De/Serialize with `FromStr` and `Display`](#deserialize-with-fromstr-and-display)
5. [`Duration` as seconds](#duration-as-seconds)
6. [Ignore deserialization errors](#ignore-deserialization-errors)
7. [`Maps` to `Vec` of tuples](#maps-to-vec-of-tuples)
8. [`NaiveDateTime` like UTC timestamp](#naivedatetime-like-utc-timestamp)
9. [`None` as empty `String`](#none-as-empty-string)
10. [Timestamps as seconds since UNIX epoch](#timestamps-as-seconds-since-unix-epoch)
11. [Value into JSON String](#value-into-json-string)
12. [`Vec` of tuples to `Maps`](#vec-of-tuples-to-maps)

## Switching from serde's with to `serde_as`

Expand Down Expand Up @@ -286,6 +287,19 @@ some_other_lib::define_some_type!();

## De/Serialize Implementations Available

### Big Array support (Rust 1.51+)

Support for arrays of arbitrary size.

```ignore
// Rust
#[serde_as(as = "[[_; 64]; 33]")]
value: [[u8; 64]; 33],
// JSON
"value": [[0,0,0,0,0,...], [0,0,0,...], ...],
```

### Bytes / `Vec<u8>` to hex string

[`Hex`]
Expand Down Expand Up @@ -497,6 +511,9 @@ value: Vec<(String, u32)>,
},
```

This operation is also available for other sequence types.
This includes `BinaryHeap<(K, V)>`, `BTreeSet<(K, V)>`, `HashSet<(K, V)>`, `LinkedList<(K, V)>`, `VecDeque<(K, V)>`, `Option<(K, V)>` and `[(K, V); N]` for all sizes of N.

The [inverse operation](#maps-to-vec-of-tuples) is also available.

[`chrono::DateTime<Local>`]: chrono_crate::DateTime
Expand Down

0 comments on commit b3441a7

Please sign in to comment.