aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md4
-rw-r--r--src/transform.rs9
-rw-r--r--tests/tests.rs13
3 files changed, 22 insertions, 4 deletions
diff --git a/README.md b/README.md
index cf5d0c1..f2a0de2 100644
--- a/README.md
+++ b/README.md
@@ -90,8 +90,10 @@ Dynamize also understands if you wrap associated types in the following types:
* `Option<_>`
* `Result<_, _>`
* `some::module::Result<_>` (type alias with fixed error type)
-* `Vec<_>`, `VecDeque<_>`,`LinkedList<_>`
* `&mut dyn Iterator<Item = _>`
+* `Vec<_>`, `VecDeque<_>`,`LinkedList<_>`
+* `HashSet<_>`, `BinaryHeap<_>`, `BTreeSet<_>`
+ (these only work with `Into`-bounded associated types because they require `Eq`)
Note that since these are resolved recursively you can actually nest these
arbitrarily so e.g. the following also just works:
diff --git a/src/transform.rs b/src/transform.rs
index 3f1c313..e9da115 100644
--- a/src/transform.rs
+++ b/src/transform.rs
@@ -24,8 +24,13 @@ pub enum TransformError {
fn is_supported_collection(ident: &Ident) -> bool {
// collections added here must implement IntoIterator & FromIterator
- // FromIterator must not require bounds like Eq or Ord since these are Self-referential
- ident == "Vec" || ident == "VecDeque" || ident == "LinkedList"
+ // when adding a type here don't forget to document it in the README
+ ident == "Vec"
+ || ident == "VecDeque"
+ || ident == "LinkedList"
+ || ident == "HashSet"
+ || ident == "BinaryHeap"
+ || ident == "BTreeSet"
}
impl AssocTypeConversions<'_> {
diff --git a/tests/tests.rs b/tests/tests.rs
index 7801cfc..e004d61 100644
--- a/tests/tests.rs
+++ b/tests/tests.rs
@@ -204,7 +204,7 @@ fn test3<T: TypeWithSuper>(some: T) {
println!("{}", dyn_trait);
}
-use std::collections::{LinkedList, VecDeque};
+use std::collections::{BTreeSet, BinaryHeap, HashSet, LinkedList, VecDeque};
#[dynamize::dynamize]
trait Collections {
@@ -220,6 +220,17 @@ trait Collections {
}
#[dynamize::dynamize]
+trait CollectionsRequiringEq {
+ type A: Into<String>;
+
+ fn hashset(&self) -> HashSet<Self::A>;
+
+ fn binary_heap(&self) -> BinaryHeap<Self::A>;
+
+ fn btree_set(&self) -> BTreeSet<Self::A>;
+}
+
+#[dynamize::dynamize]
trait ReturnIter {
type A: std::error::Error;