Skip to content

Commit 4895230

Browse files
committed
Add macro docs, move details there
1 parent 3ad378d commit 4895230

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

README.md

+4-3
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,14 @@ trait LocalIntFactory {
1212
async fn make(&self) -> i32;
1313
// ..or..
1414
fn stream(&self) -> impl Iterator<Item = i32>;
15-
fn call(&self) -> u32;
1615
}
1716
```
1817

19-
Which creates a new `IntFactory: Send` trait and additionally bounds `IntFactory::make(): Send` and `IntFactory::stream(): Send`. Ordinary methods are not affected.
18+
Which creates a new `IntFactory: Send` trait and additionally bounds `IntFactory::make(): Send` and `IntFactory::stream(): Send`. Implementers of the trait can choose to implement the variant instead of the original trait.
2019

21-
Implementers of the trait can choose to implement the variant instead of the original trait. The macro creates a blanket impl which ensures that any type which implements the variant also implements the original trait.
20+
For more details, see the docs for [`trait_variant::make`].
21+
22+
[`trait_variant::make`]: https://docs.rs/trait-variant/latest/trait_variant/attr.make.html
2223

2324
#### License and usage notes
2425

trait-variant/src/lib.rs

+28
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,34 @@
1010

1111
mod variant;
1212

13+
/// Creates a specialized version of a base trait that adds bounds to `async
14+
/// fn` and/or `-> impl Trait` return types.
15+
///
16+
/// ```
17+
/// #[trait_variant::make(IntFactory: Send)]
18+
/// trait LocalIntFactory {
19+
/// async fn make(&self) -> i32;
20+
/// fn stream(&self) -> impl Iterator<Item = i32>;
21+
/// fn call(&self) -> u32;
22+
/// }
23+
/// ```
24+
///
25+
/// The above example causes a second trait called `IntFactory` to be created:
26+
///
27+
/// ```
28+
/// # use core::future::Future;
29+
/// trait IntFactory: Send {
30+
/// fn make(&self) -> impl Future<Output = i32> + Send;
31+
/// fn stream(&self) -> impl Iterator<Item = i32> + Send;
32+
/// fn call(&self) -> u32;
33+
/// }
34+
/// ```
35+
///
36+
/// Note that ordinary methods such as `call` are not affected.
37+
///
38+
/// Implementers of the trait can choose to implement the variant instead of the
39+
/// original trait. The macro creates a blanket impl which ensures that any type
40+
/// which implements the variant also implements the original trait.
1341
#[proc_macro_attribute]
1442
pub fn make(
1543
attr: proc_macro::TokenStream,

0 commit comments

Comments
 (0)