ormlite_attr/
ident.rs

1//! This ident needs to exist because the proc_macro2 idents are not Send.
2use proc_macro2::TokenStream;
3use quote::TokenStreamExt;
4
5#[derive(Clone, Debug, Hash, PartialEq, Eq)]
6pub struct Ident(String);
7
8impl Ident {
9    pub fn as_ref(&self) -> &String {
10        &self.0
11    }
12}
13
14impl From<&proc_macro2::Ident> for Ident {
15    fn from(ident: &proc_macro2::Ident) -> Self {
16        Ident(ident.to_string())
17    }
18}
19
20impl From<&str> for Ident {
21    fn from(ident: &str) -> Self {
22        Ident(ident.to_string())
23    }
24}
25
26impl From<String> for Ident {
27    fn from(ident: String) -> Self {
28        Ident(ident)
29    }
30}
31
32impl From<&String> for Ident {
33    fn from(ident: &String) -> Self {
34        Ident(ident.clone())
35    }
36}
37
38impl quote::ToTokens for Ident {
39    fn to_tokens(&self, tokens: &mut TokenStream) {
40        tokens.append(proc_macro2::Ident::new(&self.0, proc_macro2::Span::call_site()))
41    }
42}
43
44impl std::fmt::Display for Ident {
45    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
46        write!(f, "{}", self.0)
47    }
48}
49
50impl<T> PartialEq<T> for Ident
51where
52    T: AsRef<str>,
53{
54    fn eq(&self, t: &T) -> bool {
55        let t = t.as_ref();
56        self.0.as_str() == t
57    }
58}