diff options
Diffstat (limited to 'src/parse_trait_sig.rs')
-rw-r--r-- | src/parse_trait_sig.rs | 20 |
1 files changed, 8 insertions, 12 deletions
diff --git a/src/parse_trait_sig.rs b/src/parse_trait_sig.rs index 76402ac..508e131 100644 --- a/src/parse_trait_sig.rs +++ b/src/parse_trait_sig.rs @@ -6,10 +6,10 @@ use syn::{ }; use syn::{Ident, Signature, TypeImplTrait}; +use crate::match_assoc_type; use crate::parse_assoc_type::BoxType; -use crate::syn_utils::{find_in_type, trait_bounds, TypeMatcher}; +use crate::syn_utils::{iter_type, trait_bounds, TypeOrPath}; use crate::transform::{dynamize_function_bounds, AssocTypeConversions, TransformError}; -use crate::AssocTypeMatcher; #[derive(Debug, Clone)] pub enum TypeTransform { @@ -31,14 +31,10 @@ pub enum MethodParseError { UnconvertibleAssocType, } -struct ImplTraitMatcher; -impl TypeMatcher<TypeImplTrait> for ImplTraitMatcher { - fn match_type<'a>(&self, t: &'a Type) -> Option<&'a TypeImplTrait> { - if let Type::ImplTrait(impltrait) = t { - Some(impltrait) - } else { - None - } +fn filter_map_impl_trait(item: TypeOrPath) -> Option<&TypeImplTrait> { + match item { + TypeOrPath::Type(Type::ImplTrait(impltrait)) => Some(impltrait), + _other => None, } } @@ -58,10 +54,10 @@ pub fn parse_trait_signature( // provide better error messages for associated types in params for input in &signature.inputs { if let FnArg::Typed(pattype) = input { - if find_in_type(&pattype.ty, &AssocTypeMatcher).is_some() { + if iter_type(&pattype.ty).any(match_assoc_type) { return Err((pattype.ty.span(), MethodParseError::AssocTypeInInputs)); } - if let Some(impl_trait) = find_in_type(&pattype.ty, &ImplTraitMatcher) { + if let Some(impl_trait) = iter_type(&pattype.ty).find_map(filter_map_impl_trait) { return Err((impl_trait.span(), MethodParseError::ImplTraitInInputs)); } } |