diff options
Diffstat (limited to 'src/transform.rs')
-rw-r--r-- | src/transform.rs | 65 |
1 files changed, 30 insertions, 35 deletions
diff --git a/src/transform.rs b/src/transform.rs index 4649037..60ac6e8 100644 --- a/src/transform.rs +++ b/src/transform.rs @@ -11,7 +11,7 @@ use crate::{ filter_map_assoc_paths, match_assoc_type, parse_assoc_type::{BoxType, DestType}, parse_trait_sig::{MethodError, TypeTransform}, - syn_utils::{iter_path, iter_type}, + syn_utils::{iter_path, iter_type, type_arguments_mut}, }; #[derive(Default)] @@ -111,43 +111,38 @@ impl TypeConverter<'_> { let last_seg = path.segments.last_mut().unwrap(); if let PathArguments::AngleBracketed(args) = &mut last_seg.arguments { - if args.args.len() == 1 { - if let GenericArgument::Type(arg) = &mut args.args[0] { - if iter_type(arg).any(match_assoc_type) { - if (last_seg.ident == "Option" && path_len == 1) - || last_seg.ident == "Result" - { - return Ok(TypeTransform::Map(self.convert_type(arg)?.into())); - } else if self.known_as_collection_with_one_type(&last_seg.ident) - && path_len == 1 - { - return Ok(TypeTransform::IntoIterMapCollect(vec![ - self.convert_type(arg)? - ])); - } - } - } - } else if args.args.len() == 2 && path_len == 1 { - let mut args_iter = args.args.iter_mut(); - 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) + let mut args: Vec<_> = type_arguments_mut(&mut args.args).collect(); + + if args.len() == 1 { + if iter_type(args[0]).any(match_assoc_type) { + if (last_seg.ident == "Option" && path_len == 1) + || last_seg.ident == "Result" { - if last_seg.ident == "Result" { - return Ok(TypeTransform::Result( - self.convert_type(arg1)?.into(), - self.convert_type(arg2)?.into(), - )); - } else if self.known_as_collection_with_two_types(&last_seg.ident) { - return Ok(TypeTransform::IntoIterMapCollect(vec![ - self.convert_type(arg1)?, - self.convert_type(arg2)?, - ])); - } + return Ok(TypeTransform::Map(self.convert_type(args[0])?.into())); + } else if self.known_as_collection_with_one_type(&last_seg.ident) + && path_len == 1 + { + return Ok(TypeTransform::IntoIterMapCollect(vec![ + self.convert_type(args[0])? + ])); } } + } else if args.len() == 2 + && path_len == 1 + && (iter_type(args[0]).any(match_assoc_type) + || iter_type(args[1]).any(match_assoc_type)) + { + if last_seg.ident == "Result" { + return Ok(TypeTransform::Result( + self.convert_type(args[0])?.into(), + self.convert_type(args[1])?.into(), + )); + } else if self.known_as_collection_with_two_types(&last_seg.ident) { + return Ok(TypeTransform::IntoIterMapCollect(vec![ + self.convert_type(args[0])?, + self.convert_type(args[1])?, + ])); + } } } } |