telety_impl/alias/
index.rs

1use quote::format_ident;
2
3/// Indicates the type and index of an alias.
4#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
5pub(crate) enum Index {
6    /// An alias to the item itself, like `Self`.
7    Primary,
8    /// An alias to a top-level type in the item.
9    Secondary(usize),
10}
11
12impl Index {
13    pub(crate) fn ident(self, friendly_ident: &syn::Ident) -> syn::Ident {
14        format_ident!("{}__{friendly_ident}", self.ident_core())
15    }
16
17    pub(crate) fn ident_internal(self, friendly_ident: &syn::Ident) -> syn::Ident {
18        format_ident!("{}Internal__{friendly_ident}", self.ident_core())
19    }
20
21    pub(crate) fn ident_core(self) -> syn::Ident {
22        match self {
23            Self::Primary => format_ident!("AliasSelf"),
24            Self::Secondary(index) => format_ident!("Alias{index}"),
25        }
26    }
27}