blob: 08fcf1650419330e52d2f52de03bac05a0437562 [file] [log] [blame]
David Tolnay1e5fe232021-01-01 18:11:40 -08001use crate::syntax::{Lifetimes, NamedType, Pair, Types};
David Tolnay3abed472020-12-31 23:34:53 -08002use proc_macro2::Ident;
3
David Tolnay1e5fe232021-01-01 18:11:40 -08004#[derive(Copy, Clone)]
5pub struct Resolution<'a> {
6 pub name: &'a Pair,
7 pub generics: &'a Lifetimes,
8}
9
David Tolnay3abed472020-12-31 23:34:53 -080010impl<'a> Types<'a> {
David Tolnay1e5fe232021-01-01 18:11:40 -080011 pub fn resolve(&self, ident: &impl UnresolvedName) -> Resolution<'a> {
12 *self
13 .resolutions
David Tolnay3abed472020-12-31 23:34:53 -080014 .get(ident.ident())
15 .expect("Unable to resolve type")
16 }
17}
18
19pub trait UnresolvedName {
20 fn ident(&self) -> &Ident;
21}
22
23impl UnresolvedName for Ident {
24 fn ident(&self) -> &Ident {
25 self
26 }
27}
28
29impl UnresolvedName for NamedType {
30 fn ident(&self) -> &Ident {
31 &self.rust
32 }
33}