aboutsummaryrefslogtreecommitdiff
path: root/src/syn_utils.rs
diff options
context:
space:
mode:
authorMartin Fischer <martin@push-f.com>2021-11-19 11:49:22 +0100
committerMartin Fischer <martin@push-f.com>2021-11-19 12:09:55 +0100
commit323762d238ebb9d9b8fa65bd1290aaa39648615c (patch)
treebba4645bf2fef6307018fe9187a19687149cbfbd /src/syn_utils.rs
parenta11255acdf3b3fac12d8f51048f0bed2c0df8a11 (diff)
if first type bound isn't Into<T> auto-box it
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);