aboutsummaryrefslogtreecommitdiff
path: root/src/transform.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/transform.rs')
-rw-r--r--src/transform.rs21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/transform.rs b/src/transform.rs
index e8481bb..3f1c313 100644
--- a/src/transform.rs
+++ b/src/transform.rs
@@ -22,6 +22,12 @@ pub enum TransformError {
AssocTypeInUnsupportedType(Span),
}
+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"
+}
+
impl AssocTypeConversions<'_> {
pub fn parse_type_path(&self, type_: &mut Type) -> Result<TypeTransform, TransformError> {
if !iter_type(type_).any(match_assoc_type) {
@@ -120,6 +126,21 @@ impl AssocTypeConversions<'_> {
}
}
}
+ } else if is_supported_collection(ident) && path.segments.len() == 1 {
+ let first_seg = path.segments.first_mut().unwrap();
+
+ if let PathArguments::AngleBracketed(args) = &mut first_seg.arguments {
+ if args.args.len() == 1 {
+ if let GenericArgument::Type(generic_type) = args.args.first_mut().unwrap()
+ {
+ if iter_type(generic_type).any(match_assoc_type) {
+ return Ok(TypeTransform::Collection(
+ self.parse_type_path(generic_type)?.into(),
+ ));
+ }
+ }
+ }
+ }
} else {
let last_seg = &path.segments.last().unwrap();
if last_seg.ident == "Result" {