aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_hir/src/adt.rs30
-rw-r--r--crates/ra_hir/src/code_model_api.rs31
-rw-r--r--crates/ra_hir/src/lib.rs2
3 files changed, 34 insertions, 29 deletions
diff --git a/crates/ra_hir/src/adt.rs b/crates/ra_hir/src/adt.rs
index 935f39959..58deea1c7 100644
--- a/crates/ra_hir/src/adt.rs
+++ b/crates/ra_hir/src/adt.rs
@@ -3,7 +3,7 @@ use std::sync::Arc;
3use ra_syntax::ast::{self, NameOwner, StructFlavor}; 3use ra_syntax::ast::{self, NameOwner, StructFlavor};
4 4
5use crate::{ 5use crate::{
6 DefId, Name, AsName, Struct, Enum, 6 DefId, Name, AsName, Struct, Enum, VariantData, StructField,
7 type_ref::TypeRef, 7 type_ref::TypeRef,
8}; 8};
9 9
@@ -67,30 +67,6 @@ impl EnumData {
67 } 67 }
68} 68}
69 69
70/// A single field of an enum variant or struct
71#[derive(Debug, Clone, PartialEq, Eq)]
72pub struct StructField {
73 name: Name,
74 type_ref: TypeRef,
75}
76
77impl StructField {
78 pub fn name(&self) -> Name {
79 self.name.clone()
80 }
81 pub fn type_ref(&self) -> &TypeRef {
82 &self.type_ref
83 }
84}
85
86/// Fields of an enum variant or struct
87#[derive(Debug, Clone, PartialEq, Eq)]
88pub enum VariantData {
89 Struct(Vec<StructField>),
90 Tuple(Vec<StructField>),
91 Unit,
92}
93
94impl VariantData { 70impl VariantData {
95 pub fn new(flavor: StructFlavor) -> Self { 71 pub fn new(flavor: StructFlavor) -> Self {
96 match flavor { 72 match flavor {
@@ -122,8 +98,8 @@ impl VariantData {
122 pub(crate) fn get_field_type_ref(&self, field_name: &Name) -> Option<&TypeRef> { 98 pub(crate) fn get_field_type_ref(&self, field_name: &Name) -> Option<&TypeRef> {
123 self.fields() 99 self.fields()
124 .iter() 100 .iter()
125 .find(|f| f.name == *field_name) 101 .find(|f| f.name() == field_name)
126 .map(|f| &f.type_ref) 102 .map(|f| f.type_ref())
127 } 103 }
128 104
129 pub fn fields(&self) -> &[StructField] { 105 pub fn fields(&self) -> &[StructField] {
diff --git a/crates/ra_hir/src/code_model_api.rs b/crates/ra_hir/src/code_model_api.rs
index 25d710c73..3bb42ac58 100644
--- a/crates/ra_hir/src/code_model_api.rs
+++ b/crates/ra_hir/src/code_model_api.rs
@@ -4,7 +4,12 @@ use relative_path::RelativePathBuf;
4use ra_db::{CrateId, Cancelable, FileId}; 4use ra_db::{CrateId, Cancelable, FileId};
5use ra_syntax::{ast, TreePtr, SyntaxNode}; 5use ra_syntax::{ast, TreePtr, SyntaxNode};
6 6
7use crate::{Name, db::HirDatabase, DefId, Path, PerNs, nameres::ModuleScope, adt::VariantData}; 7use crate::{
8 Name, DefId, Path, PerNs,
9 type_ref::TypeRef,
10 nameres::ModuleScope,
11 db::HirDatabase,
12};
8 13
9/// hir::Crate describes a single crate. It's the main inteface with which 14/// hir::Crate describes a single crate. It's the main inteface with which
10/// crate's dependencies interact. Mostly, it should be just a proxy for the 15/// crate's dependencies interact. Mostly, it should be just a proxy for the
@@ -114,6 +119,30 @@ impl Module {
114 } 119 }
115} 120}
116 121
122/// A single field of an enum variant or struct
123#[derive(Debug, Clone, PartialEq, Eq)]
124pub struct StructField {
125 pub(crate) name: Name,
126 pub(crate) type_ref: TypeRef,
127}
128
129impl StructField {
130 pub fn name(&self) -> &Name {
131 &self.name
132 }
133 pub fn type_ref(&self) -> &TypeRef {
134 &self.type_ref
135 }
136}
137
138/// Fields of an enum variant or struct
139#[derive(Debug, Clone, PartialEq, Eq)]
140pub enum VariantData {
141 Struct(Vec<StructField>),
142 Tuple(Vec<StructField>),
143 Unit,
144}
145
117#[derive(Debug, Clone, PartialEq, Eq, Hash)] 146#[derive(Debug, Clone, PartialEq, Eq, Hash)]
118pub struct Struct { 147pub struct Struct {
119 pub(crate) def_id: DefId, 148 pub(crate) def_id: DefId,
diff --git a/crates/ra_hir/src/lib.rs b/crates/ra_hir/src/lib.rs
index 8eff2aea5..cd04575d1 100644
--- a/crates/ra_hir/src/lib.rs
+++ b/crates/ra_hir/src/lib.rs
@@ -59,7 +59,7 @@ pub use self::function::FnSignatureInfo;
59pub use self::code_model_api::{ 59pub use self::code_model_api::{
60 Crate, CrateDependency, 60 Crate, CrateDependency,
61 Module, ModuleSource, Problem, 61 Module, ModuleSource, Problem,
62 Struct, Enum, 62 Struct, Enum, VariantData, StructField,
63}; 63};
64 64
65pub enum Def { 65pub enum Def {