You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In the above case, `T` is bound to the `Debug` trait, but `K` is not.
234
+
In the above case, `Option<T>` is bound to the `Debug` trait, but `K` is not.
232
235
233
236
Or, you can have `educe` replicate the behaviour of `std`'s `derive`'s, where a bound is produced for *every* generic parameter, without regard to how it's used in the structure:
234
237
@@ -239,14 +242,17 @@ use educe::Educe;
239
242
240
243
#[derive(Educe)]
241
244
#[educe(Debug(bound(*)))]
242
-
struct Struct<T> {
245
+
struct Struct<T, V> {
243
246
#[educe(Debug(ignore))]
244
247
f: T,
248
+
g: Option<V>,
245
249
}
246
250
# }
247
251
```
248
252
249
-
This can be useful if you don't want to make the trait implementation part of your permanent public API. In this example, `Struct<T>` doesn't implement `Debug` unless `T` does. I.e., it has a `T: Debug` bound even though that's not needed right now. Later we might want to display `f`; we wouldn't then need to make a breaking API change by adding the bound.
253
+
Here the derived bounds are `T: Debug, V: Debug`.
254
+
255
+
This can be useful if you don't want to make the trait implementation part of your permanent public API. In this example, `Struct<T>` doesn't implement `Debug` unless `T` does. I.e., it has a `T: Debug` bound even though that's not needed right now. Later we might want to display `f`; we wouldn't then need to make a breaking API change by adding the bound. We can also change the type of `g` without affecting the `V: Debug` bound.
250
256
251
257
This was the behaviour of `Trait(bound)` in educe 0.4.x and earlier.
252
258
@@ -336,7 +342,9 @@ enum Enum<T: A> {
336
342
337
343
###### Generic Parameters Bound to the `Clone` Trait or Others
338
344
339
-
Generic parameters will be automatically bound to the `Clone` trait if necessary. If the `#[educe(Copy)]` attribute exists, they will be bound to the `Copy` trait.
345
+
Unlike the trait derives provided by the standard library,
346
+
the types associated with each field or enum variant will be automatically bound to the `Clone` trait if necessary.
347
+
If the `#[educe(Copy)]` attribute exists, they will be bound to the `Copy` trait.
340
348
341
349
```rust
342
350
# #[cfg(feature = "Clone")]
@@ -448,7 +456,8 @@ enum Enum {
448
456
449
457
###### Generic Parameters Bound to the `Copy` Trait or Others
450
458
451
-
All generic parameters will be automatically bound to the `Copy` trait.
459
+
Unlike the trait derives provided by the standard library,
460
+
the types associated with each field or enum variant will be automatically bound to the `Copy` trait.
0 commit comments