aboutsummaryrefslogtreecommitdiff
path: root/README.md
diff options
context:
space:
mode:
authorMartin Fischer <martin@push-f.com>2021-11-26 09:54:23 +0100
committerMartin Fischer <martin@push-f.com>2021-11-26 11:45:53 +0100
commit43950edc4f26a07055fb917fa8bbb262276e2a08 (patch)
treea790fdea9ab5929e6985772950999557b0f37c50 /README.md
parent74bcf35fc83c57fd7e9a31639d7dae31d4d9a050 (diff)
doc: suggest splitting traits in two
Diffstat (limited to 'README.md')
-rw-r--r--README.md22
1 files changed, 17 insertions, 5 deletions
diff --git a/README.md b/README.md
index 6a80661..3fb8d39 100644
--- a/README.md
+++ b/README.md
@@ -114,25 +114,37 @@ fn example(&self) -> Result<Vec<Self::Item>, Self::Error>;
## How does dynamize deal with method generics?
In order to be object-safe methods must not have generics, so dynamize simply
-moves them to the trait definition:
+moves them to the trait definition. For the following source code:
```rust
+#[dynamize::dynamize]
trait Gen {
- fn foobar<A>(&self, a: A) -> A;
+ type Result: std::fmt::Display;
+
+ fn foo<A>(&self, a: A) -> Self::Result;
+ fn bar<A, B>(&self, a: A, b: B) -> Self::Result;
+ fn buz(&self) -> Self::Result;
}
```
-becomes
+dynamize generates the following trait:
```rust
-trait DynGen<A> {
- fn foobar(&self, a: A) -> A;
+trait DynGen<A, B> {
+ fn foo(&self, a: A) -> Box<dyn std::fmt::Display + '_>;
+ fn bar(&self, a: A, b: B) -> Box<dyn std::fmt::Display + '_>;
+ fn buz(&self) -> Box<dyn std::fmt::Display + '_>;
}
```
If two method type parameters have the same name, dynamize enforces that they
also have the same bounds and only adds the parameter once to the trait.
+Note that in the dynamized trait calling the `buz` method now requires you to
+specify both generic types, even though they aren't actually required by the
+method. You can avoid this by splitting the original trait in two, i.e. moving
+the `buz` method to a separate trait, which can be dynamized separately.
+
## Dynamize supports async
Dynamize supports async out of the box. Since Rust however does not yet support