| David Tolnay | 7db7369 | 2019-10-20 14:51:12 -0400 | [diff] [blame^] | 1 | use proc_macro2::Ident; |
| 2 | |
| 3 | #[derive(Copy, Clone, PartialEq)] |
| 4 | pub enum Atom { |
| 5 | Bool, |
| 6 | U8, |
| 7 | U16, |
| 8 | U32, |
| 9 | U64, |
| 10 | Usize, |
| 11 | I8, |
| 12 | I16, |
| 13 | I32, |
| 14 | I64, |
| 15 | Isize, |
| 16 | CxxString, |
| 17 | RustString, |
| 18 | } |
| 19 | |
| 20 | impl Atom { |
| 21 | pub fn from(ident: &Ident) -> Option<Self> { |
| 22 | use self::Atom::*; |
| 23 | match ident.to_string().as_str() { |
| 24 | "bool" => Some(Bool), |
| 25 | "u8" => Some(U8), |
| 26 | "u16" => Some(U16), |
| 27 | "u32" => Some(U32), |
| 28 | "u64" => Some(U64), |
| 29 | "usize" => Some(Usize), |
| 30 | "i8" => Some(I8), |
| 31 | "i16" => Some(I16), |
| 32 | "i32" => Some(I32), |
| 33 | "i64" => Some(I64), |
| 34 | "isize" => Some(Isize), |
| 35 | "CxxString" => Some(CxxString), |
| 36 | "String" => Some(RustString), |
| 37 | _ => None, |
| 38 | } |
| 39 | } |
| 40 | } |