diff options
author | Martin Fischer <martin@push-f.com> | 2021-11-19 11:49:22 +0100 |
---|---|---|
committer | Martin Fischer <martin@push-f.com> | 2021-11-19 12:09:55 +0100 |
commit | 323762d238ebb9d9b8fa65bd1290aaa39648615c (patch) | |
tree | bba4645bf2fef6307018fe9187a19687149cbfbd /README.md | |
parent | a11255acdf3b3fac12d8f51048f0bed2c0df8a11 (diff) |
if first type bound isn't Into<T> auto-box it
Diffstat (limited to 'README.md')
-rw-r--r-- | README.md | 12 |
1 files changed, 10 insertions, 2 deletions
@@ -78,6 +78,14 @@ in `E` need to be mapped with `map_err()`. Dynamize also understands options and results, so e.g. `Result<Option<Self::Item>, Self::Error>` also just works. +The destination type of an associated type is +determined by looking at its first trait bound: + +* `Into<T>` is mapped to `T` + +* `SomeTrait` is mapped to `Box<dyn SomeTrait>` + (for this `SomeTrait` of course needs to be object-safe) + ## Dynamize supports async Dynamize supports async out of the box. Since Rust however does not yet support @@ -90,7 +98,7 @@ async functions in traits, you'll have to additionally use another library like #[blanket_impl_attr(async_trait)] #[async_trait] trait Client: Sync { - type Error: Into<SuperError>; + type Error: std::error::Error; async fn get(&self, url: String) -> Result<Vec<u8>, Self::Error>; } @@ -109,7 +117,7 @@ The following also just works: ```rust #[dynamize::dynamize] trait TraitWithCallback { - type A: Into<String>; + type A: SomeTrait; fn fun_with_callback<F: Fn(Self::A)>(&self, a: F); } |