Skip to content

Commit 7a54435

Browse files
committed
Document new attribute proc macro edge-cases
1 parent 38e48fb commit 7a54435

File tree

3 files changed

+118
-0
lines changed

3 files changed

+118
-0
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88
### Added
99
- Support [`ZeroizeOnDrop`](https://docs.rs/zeroize/1.5.0/zeroize/trait.ZeroizeOnDrop.html).
1010

11+
### Changed
12+
- **Breaking Change**: Changed to attribute instead of derive proc macro.
13+
1114
### Removed
1215
- **Breaking Change**: Remove support for `Zeroize(drop)`.
1316

README.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,68 @@ This will generate trait implementations for `Example` for any `T`,
2323
as opposed to std's derives, which would only implement these traits with
2424
`T: Trait` bound to the corresponding trait.
2525

26+
Multiple `derive_where` attributes can be added to an item, but only the
27+
first one should use any path qualifications. Otherwise helper attributes
28+
won't be applied to any but the first `derive_where` attribute on the item.
29+
30+
```rust
31+
#[derive_where::derive_where(Clone, Debug)]
32+
#[derive_where(Default, Hash)]
33+
struct Example<T>(PhantomData<T>);
34+
```
35+
36+
Multiple `derive_where` attributes can be added to an item, but only the
37+
first one should use any path qualifications. Otherwise helper attributes
38+
won't be applied to any but the first `derive_where` attribute on the item.
39+
40+
```rust
41+
#[derive_where::derive_where(Clone, Debug; T)]
42+
#[derive_where(PartialEq)]
43+
struct Example1<T, U> {
44+
a: u8,
45+
#[derive_where(skip)]
46+
b: u8,
47+
ph: PhantomData<(T, U)>,
48+
}
49+
50+
let var1 = Example1 {
51+
a: 42,
52+
b: 42,
53+
ph: PhantomData::<((), ())>,
54+
};
55+
let var2 = Example1 {
56+
a: 42,
57+
b: 0,
58+
ph: PhantomData::<((), ())>,
59+
};
60+
61+
// Field `b` is not compared, as expected.
62+
assert_eq!(var1, var2);
63+
64+
#[derive_where::derive_where(Clone, Debug; T)]
65+
#[derive_where::derive_where(PartialEq)]
66+
struct Example2<T, U> {
67+
a: u8,
68+
#[derive_where(skip)]
69+
b: u8,
70+
ph: PhantomData<(T, U)>,
71+
}
72+
73+
let var1 = Example2 {
74+
a: 42,
75+
b: 42,
76+
ph: PhantomData::<((), ())>,
77+
};
78+
let var2 = Example2 {
79+
a: 42,
80+
b: 0,
81+
ph: PhantomData::<((), ())>,
82+
};
83+
84+
// Field `b` is compared!
85+
assert_ne!(var1, var2);
86+
```
87+
2688
In addition, the following convenience options are available:
2789

2890
### Generic type bounds

src/lib.rs

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,59 @@
2525
//! as opposed to std's derives, which would only implement these traits with
2626
//! `T: Trait` bound to the corresponding trait.
2727
//!
28+
//! Multiple `derive_where` attributes can be added to an item, but only the
29+
//! first one should use any path qualifications. Otherwise helper attributes
30+
//! won't be applied to any but the first `derive_where` attribute on the item.
31+
//!
32+
//! ```
33+
//! # use std::marker::PhantomData;
34+
//! #[derive_where::derive_where(Clone, Debug; T)]
35+
//! #[derive_where(PartialEq)]
36+
//! struct Example1<T, U> {
37+
//! a: u8,
38+
//! #[derive_where(skip)]
39+
//! b: u8,
40+
//! ph: PhantomData<(T, U)>,
41+
//! }
42+
//!
43+
//! let var1 = Example1 {
44+
//! a: 42,
45+
//! b: 42,
46+
//! ph: PhantomData::<((), ())>,
47+
//! };
48+
//! let var2 = Example1 {
49+
//! a: 42,
50+
//! b: 0,
51+
//! ph: PhantomData::<((), ())>,
52+
//! };
53+
//!
54+
//! // Field `b` is not compared, as expected.
55+
//! assert_eq!(var1, var2);
56+
//!
57+
//! #[derive_where::derive_where(Clone, Debug; T)]
58+
//! #[derive_where::derive_where(PartialEq)]
59+
//! struct Example2<T, U> {
60+
//! a: u8,
61+
//! #[derive_where(skip)]
62+
//! b: u8,
63+
//! ph: PhantomData<(T, U)>,
64+
//! }
65+
//!
66+
//! let var1 = Example2 {
67+
//! a: 42,
68+
//! b: 42,
69+
//! ph: PhantomData::<((), ())>,
70+
//! };
71+
//! let var2 = Example2 {
72+
//! a: 42,
73+
//! b: 0,
74+
//! ph: PhantomData::<((), ())>,
75+
//! };
76+
//!
77+
//! // Field `b` is compared!
78+
//! assert_ne!(var1, var2);
79+
//! ```
80+
//!
2881
//! In addition, the following convenience options are available:
2982
//!
3083
//! ## Generic type bounds

0 commit comments

Comments
 (0)