1 use syn::Generics;
2 
3 use crate::usage::{IdentSet, LifetimeSet};
4 
5 /// Extension trait for pulling specific generics data from a generics AST representation.
6 pub 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.
declared_lifetimes(&self) -> LifetimeSet9     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.
declared_type_params(&self) -> IdentSet13     fn declared_type_params(&self) -> IdentSet;
14 }
15 
16 impl GenericsExt for Generics {
declared_lifetimes(&self) -> LifetimeSet17     fn declared_lifetimes(&self) -> LifetimeSet {
18         self.lifetimes().map(|lt| lt.lifetime.clone()).collect()
19     }
20 
declared_type_params(&self) -> IdentSet21     fn declared_type_params(&self) -> IdentSet {
22         self.type_params().map(|tp| tp.ident.clone()).collect()
23     }
24 }
25