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
`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:
8
10
9
11
```rust
10
12
#[trait_variant::make(IntFactory:Send)]
11
13
traitLocalIntFactory {
12
14
asyncfnmake(&self) ->i32;
13
-
// ..or..
14
15
fnstream(&self) ->implIterator<Item=i32>;
16
+
fncall(&self) ->u32;
17
+
}
18
+
```
19
+
20
+
The `trait_variant::make` would generate an additional trait called `IntFactory`:
21
+
22
+
```rust
23
+
usecore::future::Future;
24
+
25
+
traitIntFactory:Send {
26
+
fnmake(&self) ->implFuture<Output=i32> +Send;
27
+
fnstream(&self) ->implIterator<Item=i32> +Send;
28
+
fncall(&self) ->u32;
15
29
}
16
30
```
17
31
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.
19
33
20
34
For more details, see the docs for [`trait_variant::make`].
21
35
@@ -33,3 +47,4 @@ Licensed under either of [Apache License, Version 2.0](LICENSE-APACHE) or
0 commit comments