blob: 903f5610a502001c99d5cd7b3a4fb25d6784f3ce [file] [log] [blame]
David Tolnayba5eb2d2020-03-06 09:58:20 -08001use crate::syntax::Type;
David Tolnay7db73692019-10-20 14:51:12 -04002use proc_macro2::Ident;
3
4#[derive(Copy, Clone, PartialEq)]
5pub enum Atom {
6 Bool,
7 U8,
8 U16,
9 U32,
10 U64,
11 Usize,
12 I8,
13 I16,
14 I32,
15 I64,
16 Isize,
17 CxxString,
18 RustString,
19}
20
21impl Atom {
22 pub fn from(ident: &Ident) -> Option<Self> {
23 use self::Atom::*;
24 match ident.to_string().as_str() {
25 "bool" => Some(Bool),
26 "u8" => Some(U8),
27 "u16" => Some(U16),
28 "u32" => Some(U32),
29 "u64" => Some(U64),
30 "usize" => Some(Usize),
31 "i8" => Some(I8),
32 "i16" => Some(I16),
33 "i32" => Some(I32),
34 "i64" => Some(I64),
35 "isize" => Some(Isize),
36 "CxxString" => Some(CxxString),
37 "String" => Some(RustString),
38 _ => None,
39 }
40 }
41}
David Tolnayba5eb2d2020-03-06 09:58:20 -080042
43impl PartialEq<Atom> for Ident {
44 fn eq(&self, atom: &Atom) -> bool {
45 Atom::from(self) == Some(*atom)
46 }
47}
48
49impl PartialEq<Atom> for Type {
50 fn eq(&self, atom: &Atom) -> bool {
51 match self {
52 Type::Ident(ident) => ident == atom,
53 _ => false,
54 }
55 }
56}