diff options
author | Martin Fischer <martin@push-f.com> | 2021-11-22 15:57:17 +0100 |
---|---|---|
committer | Martin Fischer <martin@push-f.com> | 2021-11-22 15:57:17 +0100 |
commit | 346113bbebddbd199b61249957c7569514071e89 (patch) | |
tree | 82a1978a60faf93a00b5cc9ed4aa4f182b3d037f /README.md | |
parent | a0ec23e259359bbbd115d6159193a361c8ce24df (diff) |
support other collections via #[collection(...)]
Diffstat (limited to 'README.md')
-rw-r--r-- | README.md | 26 |
1 files changed, 26 insertions, 0 deletions
@@ -147,3 +147,29 @@ trait Client: Sync { Note that it is important that the `#[dynamize]` attribute comes before the `#[async_trait]` attribute, since dynamize must run before async_trait. + +## Using dynamize with other collections + +Dynamize automatically recognizes collections from the standard library like +`Vec<_>` and `HashMap<_, _>`. Dynamize can also work with other collection +types as long as they implement `IntoIterator` and `FromIterator`, for example +dynamize can be used with [indexmap](https://crates.io/crates/indexmap) as +follows: + +```rust ignore +#[dynamize::dynamize] +#[collection(IndexMap, 2)] +trait Trait { + type A: Into<String>; + type B: Into<i32>; + + fn example(&self) -> IndexMap<Self::A, Self::B>; +} +``` + +The passed number tells dynamize how many generic type parameters to expect. + +* for 1 dynamize expects: `Type<A>: IntoIterator<Item=A> + FromIterator<A>` +* for 2 dynamize expects: `Type<A,B>: IntoIterator<Item=(A,B)> + FromIterator<(A,B)>` +* for 3 dynamize expects: `Type<A,B,C>: IntoIterator<Item=(A,B,C)> + FromIterator<(A,B,C)>` +* etc ... |