From 3899898d75176ce3cd87f9e2acecd7e3a987dda5 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Sat, 22 Dec 2018 22:17:55 +0100 Subject: Parse integer / float types --- crates/ra_hir/src/ty/primitive.rs | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'crates/ra_hir/src/ty/primitive.rs') diff --git a/crates/ra_hir/src/ty/primitive.rs b/crates/ra_hir/src/ty/primitive.rs index 4a5ce5a97..ad79b17e4 100644 --- a/crates/ra_hir/src/ty/primitive.rs +++ b/crates/ra_hir/src/ty/primitive.rs @@ -33,6 +33,18 @@ impl IntTy { IntTy::I128 => "i128", } } + + pub fn from_string(s: &str) -> Option { + match s { + "isize" => Some(IntTy::Isize), + "i8" => Some(IntTy::I8), + "i16" => Some(IntTy::I16), + "i32" => Some(IntTy::I32), + "i64" => Some(IntTy::I64), + "i128" => Some(IntTy::I128), + _ => None, + } + } } #[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Copy)] @@ -56,6 +68,18 @@ impl UintTy { UintTy::U128 => "u128", } } + + pub fn from_string(s: &str) -> Option { + match s { + "usize" => Some(UintTy::Usize), + "u8" => Some(UintTy::U8), + "u16" => Some(UintTy::U16), + "u32" => Some(UintTy::U32), + "u64" => Some(UintTy::U64), + "u128" => Some(UintTy::U128), + _ => None, + } + } } impl fmt::Debug for UintTy { @@ -95,4 +119,12 @@ impl FloatTy { FloatTy::F64 => "f64", } } + + pub fn from_string(s: &str) -> Option { + match s { + "f32" => Some(FloatTy::F32), + "f64" => Some(FloatTy::F64), + _ => None, + } + } } -- cgit v1.2.3