From 43950edc4f26a07055fb917fa8bbb262276e2a08 Mon Sep 17 00:00:00 2001 From: Martin Fischer Date: Fri, 26 Nov 2021 09:54:23 +0100 Subject: doc: suggest splitting traits in two --- README.md | 22 +++++++++++++++++----- 1 file 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, 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(&self, a: A) -> A; + type Result: std::fmt::Display; + + fn foo(&self, a: A) -> Self::Result; + fn bar(&self, a: A, b: B) -> Self::Result; + fn buz(&self) -> Self::Result; } ``` -becomes +dynamize generates the following trait: ```rust -trait DynGen { - fn foobar(&self, a: A) -> A; +trait DynGen { + fn foo(&self, a: A) -> Box; + fn bar(&self, a: A, b: B) -> Box; + fn buz(&self) -> Box; } ``` 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 -- cgit v1.2.3