1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
use quote::format_ident;
use syn::Ident;

use crate::alias;

/// Indicates the type and index of an alias.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum Index {
    /// An alias to the item itself, like `Self`.
    Primary,
    /// An alias to a top-level type in the item.
    Secondary(usize),
}

impl Index {
    pub(crate) fn definition(&self, unique_ident: Ident) -> alias::Definition {
        alias::Definition::new(*self, unique_ident)
    }

    pub(crate) fn ident(&self) -> Ident {
        match self {
            Self::Primary => format_ident!("AliasSelf"),
            Self::Secondary(index) => format_ident!("Alias{index}"),
        }
    }
}