From fc3ab03af74cb94a5ec94d84ec15650314f613eb Mon Sep 17 00:00:00 2001 From: Emil Lauridsen Date: Sun, 29 Dec 2019 17:38:37 +0100 Subject: Add helpers for unpacking lang items --- crates/ra_hir_def/src/lang_item.rs | 44 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'crates') diff --git a/crates/ra_hir_def/src/lang_item.rs b/crates/ra_hir_def/src/lang_item.rs index cef061837..37c861a87 100644 --- a/crates/ra_hir_def/src/lang_item.rs +++ b/crates/ra_hir_def/src/lang_item.rs @@ -22,6 +22,50 @@ pub enum LangItemTarget { TraitId(TraitId), } +impl LangItemTarget { + pub fn as_enum(self) -> Option { + match self { + LangItemTarget::EnumId(id) => Some(id), + _ => None, + } + } + + pub fn as_function(self) -> Option { + match self { + LangItemTarget::FunctionId(id) => Some(id), + _ => None, + } + } + + pub fn as_impl_block(self) -> Option { + match self { + LangItemTarget::ImplBlockId(id) => Some(id), + _ => None, + } + } + + pub fn as_static(self) -> Option { + match self { + LangItemTarget::StaticId(id) => Some(id), + _ => None, + } + } + + pub fn as_struct(self) -> Option { + match self { + LangItemTarget::StructId(id) => Some(id), + _ => None, + } + } + + pub fn as_trait(self) -> Option { + match self { + LangItemTarget::TraitId(id) => Some(id), + _ => None, + } + } +} + #[derive(Default, Debug, Clone, PartialEq, Eq)] pub struct LangItems { items: FxHashMap, -- cgit v1.2.3