diff options
Diffstat (limited to 'src/transform.rs')
-rw-r--r-- | src/transform.rs | 27 |
1 files changed, 20 insertions, 7 deletions
diff --git a/src/transform.rs b/src/transform.rs index eed48c4..75138c9 100644 --- a/src/transform.rs +++ b/src/transform.rs @@ -14,10 +14,10 @@ use crate::{ trait_sig::{MethodError, TypeTransform}, }; -#[derive(Default)] pub struct TypeConverter<'a> { pub assoc_type_conversions: HashMap<Ident, DestType<'a>>, pub collections: HashMap<Ident, usize>, + pub trait_ident: Ident, } #[derive(Debug)] @@ -27,7 +27,7 @@ pub enum TransformError { ExpectedAtLeastNTypes(usize), AssocTypeAfterFirstNTypes(usize, Ident), QualifiedAssociatedType, - QualifiedSelfAssociatedType, + SelfQualifiedAsOtherTrait, } impl TypeConverter<'_> { @@ -115,7 +115,8 @@ impl TypeConverter<'_> { } if let Type::Path(TypePath { - qself: Some(qself), .. + path, + qself: Some(qself), }) = type_ { if let Type::Path(self_path) = qself.ty.as_ref() { @@ -123,10 +124,22 @@ impl TypeConverter<'_> { if !self_path.path.is_ident("Self") { return Err((self_path.span(), TransformError::QualifiedAssociatedType)); } - return Err(( - self_path.span(), - TransformError::QualifiedSelfAssociatedType, - )); + + if qself.position == 1 + && path.segments.len() == 2 + && path.segments[0].arguments.is_empty() + && path.segments[0].ident == self.trait_ident + { + let ident = &path.segments[1].ident; + let dest_type = + self.assoc_type_conversions.get(ident).ok_or_else(|| { + (ident.span(), TransformError::AssocTypeWithoutDestType) + })?; + *type_ = dest_type.get_dest(); + return Ok(dest_type.type_transformation()); + } + + return Err((path.span(), TransformError::SelfQualifiedAsOtherTrait)); } } } else if let Type::Path(TypePath { path, qself: None }) = type_ { |