@@ -12,11 +12,9 @@ generic type bounds.
12
12
## Usage
13
13
14
14
The ` derive_where ` macro can be used just like std's ` #[derive(...)] `
15
- statements, with the only caveat that it requires to derive ` DeriveWhere `
16
- ([ #27 ] ):
15
+ statements:
17
16
18
17
``` rust
19
- #[derive(DeriveWhere )]
20
18
#[derive_where(Clone , Debug )]
21
19
struct Example <T >(PhantomData <T >);
22
20
```
@@ -34,7 +32,6 @@ specified. This example will restrict the implementation for `Example` to
34
32
` T: Clone ` :
35
33
36
34
``` rust
37
- #[derive(DeriveWhere )]
38
35
#[derive_where(Clone ; T )]
39
36
struct Example <T , U >(T , PhantomData <U >);
40
37
```
@@ -45,7 +42,6 @@ bind implementation for `Example` to `T: Super`:
45
42
``` rust
46
43
trait Super : Clone {}
47
44
48
- #[derive(DeriveWhere )]
49
45
#[derive_where(Clone ; T : Super )]
50
46
struct Example <T >(PhantomData <T >);
51
47
```
@@ -65,7 +61,6 @@ impl Trait for Impl {
65
61
type Type = i32 ;
66
62
}
67
63
68
- #[derive(DeriveWhere )]
69
64
#[derive_where(Clone ; T :: Type )]
70
65
struct Example <T : Trait >(T :: Type );
71
66
```
@@ -75,7 +70,6 @@ specific constrain. It is also possible to use multiple separate
75
70
constrain specifications when required:
76
71
77
72
``` rust
78
- #[derive(DeriveWhere )]
79
73
#[derive_where(Clone ; T )]
80
74
#[derive_where(Debug ; U )]
81
75
struct Example <T , U >(PhantomData <T >, PhantomData <U >);
@@ -87,7 +81,6 @@ Deriving [`Default`] on an enum is not possible in Rust at the moment.
87
81
Derive-where allows this with a ` default ` attribute:
88
82
89
83
``` rust
90
- #[derive(DeriveWhere )]
91
84
#[derive_where(Default )]
92
85
enum Example <T > {
93
86
#[derive_where(default)]
@@ -102,7 +95,6 @@ that allow it, which are: [`Debug`], [`Hash`], [`Ord`](https://doc.rust-lang.org
102
95
[ ` PartialEq ` ] ( https://doc.rust-lang.org/core/cmp/trait.PartialEq.html ) , [ ` Zeroize ` ] and [ ` ZeroizeOnDrop ` ] .
103
96
104
97
``` rust
105
- #[derive(DeriveWhere )]
106
98
#[derive_where(Debug , PartialEq ; T )]
107
99
struct Example <T >(#[derive_where(skip)] T );
108
100
@@ -113,14 +105,12 @@ assert_eq!(Example(42), Example(0));
113
105
It is also possible to skip all fields in an item or variant if desired:
114
106
115
107
``` rust
116
- #[derive(DeriveWhere )]
117
108
#[derive_where(Debug )]
118
109
#[derive_where(skip_inner)]
119
110
struct StructExample <T >(T );
120
111
121
112
assert_eq! (format! (" {:?}" , StructExample (42 )), " StructExample" );
122
113
123
- #[derive(DeriveWhere )]
124
114
#[derive_where(Debug )]
125
115
enum EnumExample <T > {
126
116
#[derive_where(skip_inner)]
@@ -134,7 +124,6 @@ Selective skipping of fields for certain traits is also an option, both in
134
124
` skip ` and ` skip_inner ` :
135
125
136
126
``` rust
137
- #[derive(DeriveWhere )]
138
127
#[derive_where(Debug , PartialEq )]
139
128
#[derive_where(skip_inner(Debug ))]
140
129
struct Example <T >(i32 , PhantomData <T >);
@@ -156,7 +145,6 @@ assert_ne!(
156
145
This is to avoid ambiguity between another method also called ` zeroize ` .
157
146
158
147
``` rust
159
- #[derive(DeriveWhere )]
160
148
#[derive_where(Zeroize (crate = " zeroize_" ))]
161
149
struct Example (#[derive_where(Zeroize (fqs))] i32 );
162
150
@@ -189,8 +177,7 @@ and can be implemented without [`Zeroize`], otherwise it only implements
189
177
- ` crate ` : an item-level option which specifies a path to the ` zeroize `
190
178
crate in case of a re-export or rename.
191
179
192
- ```
193
- #[derive(DeriveWhere)]
180
+ ``` rust
194
181
#[derive_where(ZeroizeOnDrop (crate = " zeroize_" ))]
195
182
struct Example (i32 );
196
183
@@ -253,8 +240,8 @@ accompanied by a minor version bump. If MSRV is important to you, use
253
240
254
241
[ derivative] ( https://crates.io/crates/derivative )
255
242
([ ![ Crates.io] ( https://img.shields.io/crates/v/derivative.svg )] ( https://crates.io/crates/derivative ) )
256
- is a great alternative with many options. Notably it has no ` no_std `
257
- support .
243
+ is a great alternative with many options. Notably it doesn't support ` no_std `
244
+ and requires an extra ` #[derive(Derivative)] ` to use .
258
245
259
246
## Changelog
260
247
0 commit comments