aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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