aboutsummaryrefslogtreecommitdiff
path: root/src/syn_utils.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/syn_utils.rs')
-rw-r--r--src/syn_utils.rs13
1 files changed, 11 insertions, 2 deletions
diff --git a/src/syn_utils.rs b/src/syn_utils.rs
index 4588186..61ae27f 100644
--- a/src/syn_utils.rs
+++ b/src/syn_utils.rs
@@ -1,6 +1,6 @@
use syn::{
- punctuated::Punctuated, GenericArgument, Path, PathArguments, ReturnType, TraitBound, Type,
- TypeParamBound,
+ punctuated::Punctuated, GenericArgument, Lifetime, Path, PathArguments, ReturnType, TraitBound,
+ Type, TypeParamBound,
};
pub trait TypeMatcher<T> {
@@ -21,6 +21,15 @@ pub fn trait_bounds<T>(
})
}
+pub fn lifetime_bounds<T>(
+ bounds: &Punctuated<TypeParamBound, T>,
+) -> impl Iterator<Item = &Lifetime> {
+ bounds.iter().filter_map(|b| match b {
+ TypeParamBound::Trait(_) => None,
+ TypeParamBound::Lifetime(l) => Some(l),
+ })
+}
+
pub fn find_in_type<'a, T>(t: &'a Type, matcher: &dyn TypeMatcher<T>) -> Option<&'a T> {
if let Some(ret) = matcher.match_type(t) {
return Some(ret);