diff options
author | Martin Fischer <martin@push-f.com> | 2021-11-20 15:10:23 +0100 |
---|---|---|
committer | Martin Fischer <martin@push-f.com> | 2021-11-20 18:36:07 +0100 |
commit | 91ca29ade1ab6b90dda972c2a42a5dc529ddfb44 (patch) | |
tree | aec288a5858fe3e8a90f0357c69571e091cf85d6 /src/transform.rs | |
parent | e918eb0ab2cf6d84751f5f52b49414d382b7abbb (diff) |
refactor: traverse AST via iterators
Diffstat (limited to 'src/transform.rs')
-rw-r--r-- | src/transform.rs | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/src/transform.rs b/src/transform.rs index c3116cf..6640cf3 100644 --- a/src/transform.rs +++ b/src/transform.rs @@ -7,10 +7,10 @@ use syn::{ }; use crate::{ + filter_map_assoc_paths, match_assoc_type, parse_assoc_type::DestType, parse_trait_sig::{MethodParseError, TypeTransform}, - syn_utils::{find_in_path, find_in_type}, - AssocTypeMatcher, + syn_utils::{iter_path, iter_type}, }; #[derive(Default)] @@ -23,7 +23,7 @@ pub enum TransformError { impl AssocTypeConversions<'_> { pub fn parse_type_path(&self, type_: &mut Type) -> Result<TypeTransform, TransformError> { - let assoc_span = match find_in_type(type_, &AssocTypeMatcher) { + let assoc_span = match iter_type(type_).filter_map(filter_map_assoc_paths).next() { Some(path) => path.span(), None => return Ok(TypeTransform::NoOp), }; @@ -49,7 +49,7 @@ impl AssocTypeConversions<'_> { if args.args.len() == 1 { if let GenericArgument::Type(generic_type) = args.args.first_mut().unwrap() { - if find_in_type(generic_type, &AssocTypeMatcher).is_some() { + if iter_type(generic_type).any(match_assoc_type) { return Ok(TypeTransform::Map( self.parse_type_path(generic_type)?.into(), )); @@ -65,8 +65,8 @@ impl AssocTypeConversions<'_> { if let (GenericArgument::Type(ok_type), GenericArgument::Type(err_type)) = (args_iter.next().unwrap(), args_iter.next().unwrap()) { - if find_in_type(ok_type, &AssocTypeMatcher).is_some() - || find_in_type(err_type, &AssocTypeMatcher).is_some() + if iter_type(ok_type).any(match_assoc_type) + || iter_type(err_type).any(match_assoc_type) { return Ok(TypeTransform::Result( self.parse_type_path(ok_type)?.into(), @@ -85,7 +85,7 @@ impl AssocTypeConversions<'_> { if let GenericArgument::Type(generic_type) = args.args.first_mut().unwrap() { - if find_in_type(generic_type, &AssocTypeMatcher).is_some() { + if iter_type(generic_type).any(match_assoc_type) { return Ok(TypeTransform::Map( self.parse_type_path(generic_type)?.into(), )); @@ -146,7 +146,10 @@ pub fn dynamize_function_bounds( } } } - if let Some(path) = find_in_path(&bound.path, &AssocTypeMatcher) { + if let Some(path) = iter_path(&bound.path) + .filter_map(filter_map_assoc_paths) + .next() + { return Err(( path.span(), MethodParseError::UnconvertibleAssocTypeInTraitBound, |