66
77## Description
88
9- Derive macro to simplify deriving standard and other traits with custom
10- generic type bounds.
9+ The ` derive_where ` macro can be used just like std's ` #[derive(...)] `
10+ statements, with the only caveat that it requires to derive ` DeriveWhere `
11+ ([ #27 ] ):
1112
1213## Usage
1314
@@ -17,22 +18,26 @@ generic type bounds.
1718struct Example <T >(PhantomData <T >);
1819```
1920
20- This will generate trait implementations for ` Example ` with any ` T ` ,
21- compared with std's derives, which would only implement these traits with
21+ This will generate trait implementations for ` Example ` for any ` T ` ,
22+ as opposed to std's derives, which would only implement these traits with
2223` T: Trait ` bound to the corresponding trait.
2324
2425In addition, the following convenience options are available:
2526
2627### Generic type bounds
2728
29+ Separated from the list of traits with a semi-colon, types to bind to can be
30+ specified. This example will restrict the implementation for ` Example ` to
31+ ` T: Clone ` :
32+
2833``` rust
2934#[derive(DeriveWhere )]
3035#[derive_where(Clone ; T )]
3136struct Example <T , U >(T , PhantomData <U >);
3237```
3338
34- Separating the list of trait with a semi-colon, types to bind to can be
35- specified. This will bind implementation for ` Example ` to ` T: Trait ` .
39+ It is also possible to specify the bounds to be applied. This will
40+ bind implementation for ` Example ` to ` T: Super ` :
3641
3742``` rust
3843trait Super : Clone {}
@@ -42,8 +47,9 @@ trait Super: Clone {}
4247struct Example <T >(PhantomData <T >);
4348```
4449
45- This will bind implementation for ` Example ` to ` T: Super ` . But more complex
46- trait bounds are possible:
50+ But more complex trait bounds are possible as well.
51+ The example below will restrict the implementation for ` Example ` to
52+ ` T::Type: Clone ` :
4753
4854``` rust
4955trait Trait {
@@ -61,12 +67,9 @@ impl Trait for Impl {
6167struct Example <T : Trait >(T :: Type );
6268```
6369
64- This will bind implementation for ` Example ` to ` T::Type: Super ` . Any
65- combination of options listed here can be used to satisfy a specific
66- constrain.
67-
68- It is also possible to use two separate constrain specification when
69- required:
70+ Any combination of options listed here can be used to satisfy a
71+ specific constrain. It is also possible to use multiple separate
72+ constrain specifications when required:
7073
7174``` rust
7275#[derive(DeriveWhere )]
@@ -257,3 +260,4 @@ conditions.
257260[ `Hash` ] : https://doc.rust-lang.org/core/hash/trait.Hash.html
258261[ `Zeroize` ] : https://docs.rs/zeroize/latest/zeroize/trait.Zeroize.html
259262[ `zeroize` ] : https://docs.rs/zeroize/latest/zeroize/trait.Zeroize.html#tymethod.zeroize
263+ [ #27 ] : https://github.com/ModProg/derive-where/issues/27
0 commit comments