| David Tolnay | 1e5fe23 | 2021-01-01 18:11:40 -0800 | [diff] [blame] | 1 | use crate::syntax::{Lifetimes, NamedType, Pair, Types}; |
| David Tolnay | 3abed47 | 2020-12-31 23:34:53 -0800 | [diff] [blame] | 2 | use proc_macro2::Ident; |
| 3 | |
| David Tolnay | 1e5fe23 | 2021-01-01 18:11:40 -0800 | [diff] [blame] | 4 | #[derive(Copy, Clone)] |
| 5 | pub struct Resolution<'a> { |
| 6 | pub name: &'a Pair, |
| 7 | pub generics: &'a Lifetimes, |
| 8 | } |
| 9 | |
| David Tolnay | 3abed47 | 2020-12-31 23:34:53 -0800 | [diff] [blame] | 10 | impl<'a> Types<'a> { |
| David Tolnay | 1e5fe23 | 2021-01-01 18:11:40 -0800 | [diff] [blame] | 11 | pub fn resolve(&self, ident: &impl UnresolvedName) -> Resolution<'a> { |
| 12 | *self |
| 13 | .resolutions |
| David Tolnay | 3abed47 | 2020-12-31 23:34:53 -0800 | [diff] [blame] | 14 | .get(ident.ident()) |
| 15 | .expect("Unable to resolve type") |
| 16 | } |
| 17 | } |
| 18 | |
| 19 | pub trait UnresolvedName { |
| 20 | fn ident(&self) -> &Ident; |
| 21 | } |
| 22 | |
| 23 | impl UnresolvedName for Ident { |
| 24 | fn ident(&self) -> &Ident { |
| 25 | self |
| 26 | } |
| 27 | } |
| 28 | |
| 29 | impl UnresolvedName for NamedType { |
| 30 | fn ident(&self) -> &Ident { |
| 31 | &self.rust |
| 32 | } |
| 33 | } |