Skip to content

Commit

Permalink
Add documentation for the Bytes type and add a changelog entry
Browse files Browse the repository at this point in the history
  • Loading branch information
jonasbb committed Mar 12, 2021
1 parent be1f2d3 commit 1b9c5a6
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 11 deletions.
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,21 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
},
```

* The `Bytes` type is heavily inspired by `serde_bytes` and ports it to the `serde_as` system.

```rust
#[serde_as(as = "Bytes")]
value: Vec<u8>,
```

Compared to `serde_bytes` these improvements are available

1. Integration with the `serde_as` annotation (see [serde-bytes#14][serde-bytes-complex]).
2. Implementation for arrays of arbitrary size (Rust 1.51+) (see [serde-bytes#26][serde-bytes-arrays]).

[serde-bytes-complex]: https://github.com/serde-rs/bytes/issues/14
[serde-bytes-arrays]: https://github.com/serde-rs/bytes/issues/26

## [1.6.4] - 2021-02-16

### 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 @@ -17,17 +17,18 @@ The basic design of the system was done by [@markazmierczak](https://github.com/
5. [Re-exporting `serde_as`](#re-exporting-serde_as)
2. [De/Serialize Implementations Available](#deserialize-implementations-available)
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)
2. [`Bytes` with more efficiency](#bytes-with-more-efficiency)
3. [Bytes / `Vec<u8>` to hex string](#bytes--vecu8-to-hex-string)
4. [`Default` from `null`](#default-from-null)
5. [De/Serialize with `FromStr` and `Display`](#deserialize-with-fromstr-and-display)
6. [`Duration` as seconds](#duration-as-seconds)
7. [Ignore deserialization errors](#ignore-deserialization-errors)
8. [`Maps` to `Vec` of tuples](#maps-to-vec-of-tuples)
9. [`NaiveDateTime` like UTC timestamp](#naivedatetime-like-utc-timestamp)
10. [`None` as empty `String`](#none-as-empty-string)
11. [Timestamps as seconds since UNIX epoch](#timestamps-as-seconds-since-unix-epoch)
12. [Value into JSON String](#value-into-json-string)
13. [`Vec` of tuples to `Maps`](#vec-of-tuples-to-maps)

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

Expand Down Expand Up @@ -300,6 +301,21 @@ value: [[u8; 64]; 33],
"value": [[0,0,0,0,0,...], [0,0,0,...], ...],
```

### `Bytes` with more efficiency

[`Bytes`]

More efficient serialization for byte slices and similar.

```ignore
// Rust
#[serde_as(as = "Bytes")]
value: Vec<u8>,
// JSON
"value": [0, 1, 2, 3, ...],
```

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

[`Hex`]
Expand Down Expand Up @@ -516,6 +532,7 @@ This includes `BinaryHeap<(K, V)>`, `BTreeSet<(K, V)>`, `HashSet<(K, V)>`, `Link

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

[`Bytes`]: crate::Bytes
[`chrono::DateTime<Local>`]: chrono_crate::DateTime
[`chrono::DateTime<Utc>`]: chrono_crate::DateTime
[`chrono::Duration`]: https://docs.rs/chrono/latest/chrono/struct.Duration.html
Expand Down

0 comments on commit 1b9c5a6

Please sign in to comment.