mir/
ident.rs

1use std::fmt::{Display, Formatter};
2
3use quote::TokenStreamExt;
4
5/// Localized string
6#[derive(Debug, Clone, Eq, PartialEq, Hash, Default)]
7pub struct Ident(pub String);
8
9impl Ident {
10    pub fn new(s: &'static str) -> Self {
11        Ident(s.into())
12    }
13}
14
15impl Display for Ident {
16    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
17        write!(f, "{}", self.0)
18    }
19}
20
21impl PartialEq<str> for Ident {
22    fn eq(&self, other: &str) -> bool {
23        self.0 == *other
24    }
25}
26
27impl PartialEq<&str> for Ident {
28    fn eq(&self, other: &&str) -> bool {
29        self.0 == *other
30    }
31}
32
33impl quote::ToTokens for Ident {
34    fn to_tokens(&self, tokens: &mut proc_macro2::TokenStream) {
35        tokens.append(proc_macro2::Ident::new(
36            &self.0,
37            proc_macro2::Span::call_site(),
38        ))
39    }
40}
41
42impl From<Ident> for proc_macro2::TokenStream {
43    fn from(val: Ident) -> Self {
44        let mut tok = proc_macro2::TokenStream::new();
45        tok.append(proc_macro2::Ident::new(
46            &val.0,
47            proc_macro2::Span::call_site(),
48        ));
49        tok
50    }
51}