diff options
Diffstat (limited to 'src/lib.rs')
-rw-r--r-- | src/lib.rs | 56 |
1 files changed, 32 insertions, 24 deletions
@@ -78,7 +78,7 @@ pub fn dynamize(_attr: TokenStream, input: TokenStream) -> TokenStream { ) } Ok((ident, type_)) => { - assoc_type_conversions.0.insert(ident, type_); + assoc_type_conversions.0.insert(ident.clone(), type_); } } } @@ -181,32 +181,40 @@ pub fn dynamize(_attr: TokenStream, input: TokenStream) -> TokenStream { let fun_name = &new_method.sig.ident; - let args = new_method - .sig - .inputs - .iter() - .enumerate() - .map(|(idx, arg)| match arg { - syn::FnArg::Receiver(_) => quote! {self}, - syn::FnArg::Typed(pat_type) => match pat_type.pat.as_ref() { - syn::Pat::Ident(ident) => match &parsed_method.inputs[idx] { - None => ident.ident.to_token_stream(), - Some(transforms) => { - let args = (0..transforms.len()).map(|i| format_ident!("a{}", i)); - let mut calls: Vec<_> = - args.clone().map(|i| i.into_token_stream()).collect(); - for i in 0..calls.len() { - transforms[i].append_conversion(&mut calls[i]); + let args = new_method.sig.inputs.iter().map(|arg| match arg { + syn::FnArg::Receiver(_) => quote! {self}, + syn::FnArg::Typed(pat_type) => match pat_type.pat.as_ref() { + syn::Pat::Ident(ident) => { + // FUTURE: use try block + if let Type::Path(path) = &*pat_type.ty { + if let Some(type_ident) = path.path.get_ident() { + if let Some(transforms) = + parsed_method.type_param_transforms.get(type_ident) + { + let args = (0..transforms.len()).map(|i| format_ident!("a{}", i)); + let mut calls: Vec<_> = + args.clone().map(|i| i.into_token_stream()).collect(); + for i in 0..calls.len() { + transforms[i].append_conversion(&mut calls[i]); + } + let move_opt = new_method.sig.asyncness.map(|_| quote! {move}); + quote!(#move_opt |#(#args),*| #ident(#(#calls),*)) + } else { + ident.ident.to_token_stream() } - let move_opt = new_method.sig.asyncness.map(|_| quote! {move}); - quote!(#move_opt |#(#args),*| #ident(#(#calls),*)) + } else { + ident.ident.to_token_stream() } - }, - _other => { - panic!("unexpected"); + } else { + ident.ident.to_token_stream() } - }, - }); + } + + _other => { + panic!("unexpected"); + } + }, + }); // in order for a trait to be object-safe its methods may not have // generics so we convert method generics into trait generics |