Skip to content

Commit 8cd33d4

Browse files
authored
Merge pull request #23 from t3hmrman/refactor/docs/add-example-to-readme
refactor(docs): add example to README
2 parents 6a5e7ab + 48b62b1 commit 8cd33d4

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

README.md

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,35 @@
11
[![Latest Version]][crates.io] [![Documentation]][docs.rs] [![GHA Status]][GitHub Actions] ![License]
22

3-
Utilities for working with impl traits in Rust.
3+
Utilities for working with `impl Trait`s in Rust.
44

55
## `trait_variant`
66

7-
`trait_variant` generates a specialized version of a base trait that uses `async fn` and/or `-> impl Trait`. For example, if you want a `Send`able version of your trait, you'd write:
7+
`trait_variant` generates a specialized version of a base trait that uses `async fn` and/or `-> impl Trait`.
8+
9+
For example, if you want a [`Send`][rust-std-send]able version of your trait, you'd write:
810

911
```rust
1012
#[trait_variant::make(IntFactory: Send)]
1113
trait LocalIntFactory {
1214
async fn make(&self) -> i32;
13-
// ..or..
1415
fn stream(&self) -> impl Iterator<Item = i32>;
16+
fn call(&self) -> u32;
17+
}
18+
```
19+
20+
The `trait_variant::make` would generate an additional trait called `IntFactory`:
21+
22+
```rust
23+
use core::future::Future;
24+
25+
trait IntFactory: Send {
26+
fn make(&self) -> impl Future<Output = i32> + Send;
27+
fn stream(&self) -> impl Iterator<Item = i32> + Send;
28+
fn call(&self) -> u32;
1529
}
1630
```
1731

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.
32+
Implementers can choose to implement either `LocalIntFactory` or `IntFactory` as appropriate.
1933

2034
For more details, see the docs for [`trait_variant::make`].
2135

@@ -33,3 +47,4 @@ Licensed under either of [Apache License, Version 2.0](LICENSE-APACHE) or
3347
[Documentation]: https://img.shields.io/docsrs/trait-variant
3448
[docs.rs]: https://docs.rs/trait-variant
3549
[License]: https://img.shields.io/crates/l/trait-variant.svg
50+
[rust-std-send]: https://doc.rust-lang.org/std/marker/trait.Send.html

0 commit comments

Comments
 (0)