diff options
Diffstat (limited to 'src/transform.rs')
-rw-r--r-- | src/transform.rs | 26 |
1 files changed, 19 insertions, 7 deletions
diff --git a/src/transform.rs b/src/transform.rs index 4dc88f0..4625f4c 100644 --- a/src/transform.rs +++ b/src/transform.rs @@ -33,6 +33,12 @@ fn is_supported_collection(ident: &Ident) -> bool { || ident == "BTreeSet" } +fn is_supported_collection_map(ident: &Ident) -> bool { + // collections added here must implement IntoIterator & FromIterator + // when adding a type here don't forget to document it in the README + ident == "HashMap" || ident == "BTreeMap" +} + impl AssocTypeConversions<'_> { pub fn parse_type_path(&self, type_: &mut Type) -> Result<TypeTransform, TransformError> { if !iter_type(type_).any(match_assoc_type) { @@ -123,14 +129,20 @@ impl AssocTypeConversions<'_> { if let (GenericArgument::Type(arg1), GenericArgument::Type(arg2)) = (args_iter.next().unwrap(), args_iter.next().unwrap()) { - if (iter_type(arg1).any(match_assoc_type) - || iter_type(arg2).any(match_assoc_type)) - && last_seg.ident == "Result" + if iter_type(arg1).any(match_assoc_type) + || iter_type(arg2).any(match_assoc_type) { - return Ok(TypeTransform::Result( - self.parse_type_path(arg1)?.into(), - self.parse_type_path(arg2)?.into(), - )); + if last_seg.ident == "Result" { + return Ok(TypeTransform::Result( + self.parse_type_path(arg1)?.into(), + self.parse_type_path(arg2)?.into(), + )); + } else if is_supported_collection_map(&last_seg.ident) { + return Ok(TypeTransform::CollectionMap( + self.parse_type_path(arg1)?.into(), + self.parse_type_path(arg2)?.into(), + )); + } } } } |