1use syn::Generics;
2
3use crate::usage::{IdentSet, LifetimeSet};
4
5/// Extension trait for pulling specific generics data from a generics AST representation.
6pub trait GenericsExt {
7 /// Get the set of all lifetimes declared by the syntax element.
8 /// This does not look for usage of the lifetime; see `UsesLifetimes` for that.
9 fn declared_lifetimes(&self) -> LifetimeSet;
10
11 /// Get the set of all type parameters declared by the syntax element.
12 /// This does not look for usage of the type parameter; see `UsesTypeParams` for that.
13 fn declared_type_params(&self) -> IdentSet;
14}
15
16impl GenericsExt for Generics {
17 fn declared_lifetimes(&self) -> LifetimeSet {
18 self.lifetimes().map(|lt: &LifetimeDef| lt.lifetime.clone()).collect()
19 }
20
21 fn declared_type_params(&self) -> IdentSet {
22 self.type_params().map(|tp: &TypeParam| tp.ident.clone()).collect()
23 }
24}
25