aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_def/src
diff options
context:
space:
mode:
authorEmil Lauridsen <[email protected]>2019-12-29 16:38:37 +0000
committerEmil Lauridsen <[email protected]>2019-12-29 16:38:37 +0000
commitfc3ab03af74cb94a5ec94d84ec15650314f613eb (patch)
tree116bdc0f05a3362a7a0dc6313299faad19f6ea9d /crates/ra_hir_def/src
parent523b4cbc602447b14202dd2520f84241bb07c4e2 (diff)
Add helpers for unpacking lang items
Diffstat (limited to 'crates/ra_hir_def/src')
-rw-r--r--crates/ra_hir_def/src/lang_item.rs44
1 files changed, 44 insertions, 0 deletions
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 {
22 TraitId(TraitId), 22 TraitId(TraitId),
23} 23}
24 24
25impl LangItemTarget {
26 pub fn as_enum(self) -> Option<EnumId> {
27 match self {
28 LangItemTarget::EnumId(id) => Some(id),
29 _ => None,
30 }
31 }
32
33 pub fn as_function(self) -> Option<FunctionId> {
34 match self {
35 LangItemTarget::FunctionId(id) => Some(id),
36 _ => None,
37 }
38 }
39
40 pub fn as_impl_block(self) -> Option<ImplId> {
41 match self {
42 LangItemTarget::ImplBlockId(id) => Some(id),
43 _ => None,
44 }
45 }
46
47 pub fn as_static(self) -> Option<StaticId> {
48 match self {
49 LangItemTarget::StaticId(id) => Some(id),
50 _ => None,
51 }
52 }
53
54 pub fn as_struct(self) -> Option<StructId> {
55 match self {
56 LangItemTarget::StructId(id) => Some(id),
57 _ => None,
58 }
59 }
60
61 pub fn as_trait(self) -> Option<TraitId> {
62 match self {
63 LangItemTarget::TraitId(id) => Some(id),
64 _ => None,
65 }
66 }
67}
68
25#[derive(Default, Debug, Clone, PartialEq, Eq)] 69#[derive(Default, Debug, Clone, PartialEq, Eq)]
26pub struct LangItems { 70pub struct LangItems {
27 items: FxHashMap<SmolStr, LangItemTarget>, 71 items: FxHashMap<SmolStr, LangItemTarget>,