Skip to content

Commit 89a2738

Browse files
ModProgdaxpedda
authored andcommitted
Some doc improvements
1 parent 76bfed5 commit 89a2738

File tree

2 files changed

+37
-26
lines changed

2 files changed

+37
-26
lines changed

README.md

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
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.
1718
struct 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

2425
In 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)]
3136
struct 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
3843
trait Super: Clone {}
@@ -42,8 +47,9 @@ trait Super: Clone {}
4247
struct 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
4955
trait Trait {
@@ -61,12 +67,9 @@ impl Trait for Impl {
6167
struct 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

src/lib.rs

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
//!
1212
//! # Usage
1313
//!
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]):
17+
//!
1418
//! ```
1519
//! # use std::marker::PhantomData;
1620
//! # use derive_where::DeriveWhere;
@@ -19,14 +23,18 @@
1923
//! struct Example<T>(PhantomData<T>);
2024
//! ```
2125
//!
22-
//! This will generate trait implementations for `Example` with any `T`,
23-
//! compared with std's derives, which would only implement these traits with
26+
//! This will generate trait implementations for `Example` for any `T`,
27+
//! as opposed to std's derives, which would only implement these traits with
2428
//! `T: Trait` bound to the corresponding trait.
2529
//!
2630
//! In addition, the following convenience options are available:
2731
//!
2832
//! ## Generic type bounds
2933
//!
34+
//! Separated from the list of traits with a semi-colon, types to bind to can be
35+
//! specified. This example will restrict the implementation for `Example` to
36+
//! `T: Clone`:
37+
//!
3038
//! ```
3139
//! # use std::marker::PhantomData;
3240
//! # use derive_where::DeriveWhere;
@@ -35,8 +43,8 @@
3543
//! struct Example<T, U>(T, PhantomData<U>);
3644
//! ```
3745
//!
38-
//! Separating the list of trait with a semi-colon, types to bind to can be
39-
//! specified. This will bind implementation for `Example` to `T: Trait`.
46+
//! It is also possible to specify the bounds to be applied. This will
47+
//! bind implementation for `Example` to `T: Super`:
4048
//!
4149
//! ```
4250
//! # use std::marker::PhantomData;
@@ -48,8 +56,9 @@
4856
//! struct Example<T>(PhantomData<T>);
4957
//! ```
5058
//!
51-
//! This will bind implementation for `Example` to `T: Super`. But more complex
52-
//! trait bounds are possible:
59+
//! But more complex trait bounds are possible as well.
60+
//! The example below will restrict the implementation for `Example` to
61+
//! `T::Type: Clone`:
5362
//!
5463
//! ```
5564
//! # use std::marker::PhantomData;
@@ -69,12 +78,9 @@
6978
//! struct Example<T: Trait>(T::Type);
7079
//! ```
7180
//!
72-
//! This will bind implementation for `Example` to `T::Type: Super`. Any
73-
//! combination of options listed here can be used to satisfy a specific
74-
//! constrain.
75-
//!
76-
//! It is also possible to use two separate constrain specification when
77-
//! required:
81+
//! Any combination of options listed here can be used to satisfy a
82+
//! specific constrain. It is also possible to use multiple separate
83+
//! constrain specifications when required:
7884
//!
7985
//! ```
8086
//! # use std::marker::PhantomData;
@@ -293,6 +299,7 @@
293299
//! [`Hash`]: core::hash::Hash
294300
//! [`Zeroize`]: https://docs.rs/zeroize/latest/zeroize/trait.Zeroize.html
295301
//! [`zeroize`]: https://docs.rs/zeroize/latest/zeroize/trait.Zeroize.html#tymethod.zeroize
302+
//! [#27]: https://github.com/ModProg/derive-where/issues/27
296303
297304
// MSRV: needed to support a lower MSRV.
298305
extern crate proc_macro;

0 commit comments

Comments
 (0)