aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/transform.rs95
1 files changed, 35 insertions, 60 deletions
diff --git a/src/transform.rs b/src/transform.rs
index 0fee2e6..4dc88f0 100644
--- a/src/transform.rs
+++ b/src/transform.rs
@@ -86,80 +86,55 @@ impl AssocTypeConversions<'_> {
}
if let Type::Path(TypePath { path, qself: None }) = type_ {
- let ident = &path.segments[0].ident;
-
- if ident == "Self" && path.segments.len() == 2 {
- let ident = &path.segments.last().unwrap().ident;
- let dest_type = self
- .0
- .get(ident)
- .ok_or_else(|| TransformError::UnconvertibleAssocType(ident.span()))?;
- *type_ = dest_type.get_dest();
- return Ok(dest_type.type_transformation());
- } else if ident == "Option" && path.segments.len() == 1 {
- let first_seg = &mut path.segments[0];
+ if path.segments[0].ident == "Self" {
+ if path.segments.len() == 2 {
+ let ident = &path.segments.last().unwrap().ident;
+ let dest_type = self
+ .0
+ .get(ident)
+ .ok_or_else(|| TransformError::UnconvertibleAssocType(ident.span()))?;
+ *type_ = dest_type.get_dest();
+ return Ok(dest_type.type_transformation());
+ }
+ } else {
+ let path_len = path.segments.len();
+ let last_seg = path.segments.last_mut().unwrap();
- if let PathArguments::AngleBracketed(args) = &mut first_seg.arguments {
+ if let PathArguments::AngleBracketed(args) = &mut last_seg.arguments {
if args.args.len() == 1 {
- if let GenericArgument::Type(generic_type) = &mut args.args[0] {
- if iter_type(generic_type).any(match_assoc_type) {
- return Ok(TypeTransform::Map(
- self.parse_type_path(generic_type)?.into(),
- ));
+ 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.parse_type_path(arg)?.into(),
+ ));
+ } else if is_supported_collection(&last_seg.ident) && path_len == 1
+ {
+ return Ok(TypeTransform::Collection(
+ self.parse_type_path(arg)?.into(),
+ ));
+ }
}
}
- }
- }
- } else if ident == "Result" && path.segments.len() == 1 {
- let first_seg = &mut path.segments[0];
-
- if let PathArguments::AngleBracketed(args) = &mut first_seg.arguments {
- if args.args.len() == 2 {
+ } else if args.args.len() == 2 && path_len == 1 {
let mut args_iter = args.args.iter_mut();
- if let (GenericArgument::Type(ok_type), GenericArgument::Type(err_type)) =
+ if let (GenericArgument::Type(arg1), GenericArgument::Type(arg2)) =
(args_iter.next().unwrap(), args_iter.next().unwrap())
{
- if iter_type(ok_type).any(match_assoc_type)
- || iter_type(err_type).any(match_assoc_type)
+ if (iter_type(arg1).any(match_assoc_type)
+ || iter_type(arg2).any(match_assoc_type))
+ && last_seg.ident == "Result"
{
return Ok(TypeTransform::Result(
- self.parse_type_path(ok_type)?.into(),
- self.parse_type_path(err_type)?.into(),
- ));
- }
- }
- }
- }
- } else if is_supported_collection(ident) && path.segments.len() == 1 {
- let first_seg = &mut path.segments[0];
-
- if let PathArguments::AngleBracketed(args) = &mut first_seg.arguments {
- if args.args.len() == 1 {
- if let GenericArgument::Type(generic_type) = &mut args.args[0] {
- if iter_type(generic_type).any(match_assoc_type) {
- return Ok(TypeTransform::Collection(
- self.parse_type_path(generic_type)?.into(),
+ self.parse_type_path(arg1)?.into(),
+ self.parse_type_path(arg2)?.into(),
));
}
}
}
}
- } else {
- let last_seg = &path.segments.last().unwrap();
- if last_seg.ident == "Result" {
- 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(generic_type) = &mut args.args[0] {
- if iter_type(generic_type).any(match_assoc_type) {
- return Ok(TypeTransform::Map(
- self.parse_type_path(generic_type)?.into(),
- ));
- }
- }
- }
- }
- }
}
}