Skip to content

Commit ade4751

Browse files
committed
Add documentation
1 parent 080048c commit ade4751

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010
### Added
1111
- `no_drop` item-level option to `ZeroizeOnDrop` which does not implement
1212
`Drop` but instead only asserts that every field implements `ZeroizeOnDrop`.
13+
- Support deriving Serde's `Deserialize` and `Serialize` trait via Serde's own
14+
proc-macro.
1315

1416
### Changed
1517
- Error messages now point to crate features instead of reporting traits as

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,13 @@ assert!(!(StructExample <= StructExample));
200200
Note that it is not possible to use `incomparable` with [`Eq`] or [`Ord`] as
201201
that would break their invariants.
202202

203+
### Serde `Deserialize` and `Serialize`
204+
205+
Deriving [`Deserialize`] and [`Serialize`] works as expected. While
206+
derive-where does not offer any attribute options, regular `serde` attributes
207+
can be used. Derive-where will respect
208+
[`#[serde(crate = "...")]`](https://serde.rs/container-attrs.html#crate).
209+
203210
### `Zeroize` options
204211

205212
`Zeroize` has two options:
@@ -259,11 +266,13 @@ The following traits can be derived with derive-where:
259266
- [`Copy`]
260267
- [`Debug`]
261268
- [`Default`]
269+
- [`Deserialize`]: Only available with the `serde` crate feature.
262270
- [`Eq`]
263271
- [`Hash`]
264272
- [`Ord`]
265273
- [`PartialEq`]
266274
- [`PartialOrd`]
275+
- [`Serialize`]: Only available with the `serde` crate feature.
267276
- [`Zeroize`]: Only available with the `zeroize` crate feature.
268277
- [`ZeroizeOnDrop`]: Only available with the `zeroize` crate feature. If the
269278
`zeroize-on-drop` feature is enabled, it implements [`ZeroizeOnDrop`],
@@ -352,12 +361,14 @@ conditions.
352361
[`core::intrinsics::discriminant_value`]: https://doc.rust-lang.org/core/intrinsics/fn.discriminant_value.html
353362
[`derive_where`]: https://docs.rs/derive-where/latest/derive_where/attr.derive_where.html
354363
[`Discriminant`]: https://doc.rust-lang.org/core/mem/struct.Discriminant.html
364+
[`Deserialize`]: https://docs.rs/serde/latest/serde/derive.Deserialize.html
355365
[`Drop`]: https://doc.rust-lang.org/core/ops/trait.Drop.html
356366
[`Eq`]: https://doc.rust-lang.org/core/cmp/trait.Eq.html
357367
[`i32`]: https://doc.rust-lang.org/core/primitive.i32.html
358368
[`isize`]: https://doc.rust-lang.org/core/primitive.isize.html
359369
[`Ord`]: https://doc.rust-lang.org/core/cmp/trait.Ord.html
360370
[`PartialEq`]: https://doc.rust-lang.org/core/cmp/trait.PartialEq.html
361371
[`PartialOrd`]: https://doc.rust-lang.org/core/cmp/trait.PartialOrd.html
372+
[`Serialize`]: https://docs.rs/serde/latest/serde/derive.Serialize.html
362373
[`transmute`]: https://doc.rust-lang.org/core/mem/fn.transmute.html
363374
[`unreachable`]: https://doc.rust-lang.org/core/macro.unreachable.html

src/lib.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,13 @@
228228
//! Note that it is not possible to use `incomparable` with [`Eq`] or [`Ord`] as
229229
//! that would break their invariants.
230230
//!
231+
//! ## Serde `Deserialize` and `Serialize`
232+
//!
233+
//! Deriving [`Deserialize`] and [`Serialize`] works as expected. While
234+
//! derive-where does not offer any attribute options, regular `serde`
235+
//! attributes can be used. Derive-where will respect
236+
//! [`#[serde(crate = "...")]`](https://serde.rs/container-attrs.html#crate).
237+
//!
231238
//! ## `Zeroize` options
232239
//!
233240
//! `Zeroize` has two options:
@@ -298,11 +305,13 @@
298305
//! - [`Copy`]
299306
//! - [`Debug`]
300307
//! - [`Default`]
308+
//! - [`Deserialize`]: Only available with the `serde` crate feature.
301309
//! - [`Eq`]
302310
//! - [`Hash`]
303311
//! - [`Ord`]
304312
//! - [`PartialEq`]
305313
//! - [`PartialOrd`]
314+
//! - [`Serialize`]: Only available with the `serde` crate feature.
306315
//! - [`Zeroize`]: Only available with the `zeroize` crate feature.
307316
//! - [`ZeroizeOnDrop`]: Only available with the `zeroize` crate feature. If the
308317
//! `zeroize-on-drop` feature is enabled, it implements [`ZeroizeOnDrop`],
@@ -379,11 +388,13 @@
379388
//! [LICENSE-APACHE]: https://github.com/ModProg/derive-where/blob/main/LICENSE-APACHE
380389
//! [`Debug`]: core::fmt::Debug
381390
//! [`Default`]: core::default::Default
391+
//! [`Deserialize`]: https://docs.rs/serde/latest/serde/derive.Deserialize.html
382392
//! [`Eq`]: core::cmp::Eq
383393
//! [`Hash`]: core::hash::Hash
384394
//! [`Ord`]: core::cmp::Ord
385395
//! [`PartialEq`]: core::cmp::PartialEq
386396
//! [`PartialOrd`]: core::cmp::PartialOrd
397+
//! [`Serialize`]: https://docs.rs/serde/latest/serde/derive.Serialize.html
387398
//! [`zeroize`]: https://docs.rs/zeroize
388399
//! [`Zeroize`]: https://docs.rs/zeroize/latest/zeroize/trait.Zeroize.html
389400
//! [`ZeroizeOnDrop`]: https://docs.rs/zeroize/latest/zeroize/trait.ZeroizeOnDrop.html

0 commit comments

Comments
 (0)