aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir')
-rw-r--r--crates/ra_hir/src/adt.rs35
-rw-r--r--crates/ra_hir/src/code_model_api.rs27
2 files changed, 28 insertions, 34 deletions
diff --git a/crates/ra_hir/src/adt.rs b/crates/ra_hir/src/adt.rs
index 58deea1c7..d56570754 100644
--- a/crates/ra_hir/src/adt.rs
+++ b/crates/ra_hir/src/adt.rs
@@ -26,14 +26,6 @@ impl StructData {
26 let variant_data = Arc::new(variant_data); 26 let variant_data = Arc::new(variant_data);
27 StructData { name, variant_data } 27 StructData { name, variant_data }
28 } 28 }
29
30 pub fn name(&self) -> Option<&Name> {
31 self.name.as_ref()
32 }
33
34 pub fn variant_data(&self) -> &Arc<VariantData> {
35 &self.variant_data
36 }
37} 29}
38 30
39impl Enum { 31impl Enum {
@@ -68,7 +60,7 @@ impl EnumData {
68} 60}
69 61
70impl VariantData { 62impl VariantData {
71 pub fn new(flavor: StructFlavor) -> Self { 63 pub(crate) fn new(flavor: StructFlavor) -> Self {
72 match flavor { 64 match flavor {
73 StructFlavor::Tuple(fl) => { 65 StructFlavor::Tuple(fl) => {
74 let fields = fl 66 let fields = fl
@@ -101,29 +93,4 @@ impl VariantData {
101 .find(|f| f.name() == field_name) 93 .find(|f| f.name() == field_name)
102 .map(|f| f.type_ref()) 94 .map(|f| f.type_ref())
103 } 95 }
104
105 pub fn fields(&self) -> &[StructField] {
106 match *self {
107 VariantData::Struct(ref fields) | VariantData::Tuple(ref fields) => fields,
108 _ => &[],
109 }
110 }
111 pub fn is_struct(&self) -> bool {
112 match self {
113 VariantData::Struct(..) => true,
114 _ => false,
115 }
116 }
117 pub fn is_tuple(&self) -> bool {
118 match self {
119 VariantData::Tuple(..) => true,
120 _ => false,
121 }
122 }
123 pub fn is_unit(&self) -> bool {
124 match self {
125 VariantData::Unit => true,
126 _ => false,
127 }
128 }
129} 96}
diff --git a/crates/ra_hir/src/code_model_api.rs b/crates/ra_hir/src/code_model_api.rs
index 3bb42ac58..f06f1ae66 100644
--- a/crates/ra_hir/src/code_model_api.rs
+++ b/crates/ra_hir/src/code_model_api.rs
@@ -143,6 +143,33 @@ pub enum VariantData {
143 Unit, 143 Unit,
144} 144}
145 145
146impl VariantData {
147 pub fn fields(&self) -> &[StructField] {
148 match self {
149 VariantData::Struct(fields) | VariantData::Tuple(fields) => fields,
150 _ => &[],
151 }
152 }
153 pub fn is_struct(&self) -> bool {
154 match self {
155 VariantData::Struct(..) => true,
156 _ => false,
157 }
158 }
159 pub fn is_tuple(&self) -> bool {
160 match self {
161 VariantData::Tuple(..) => true,
162 _ => false,
163 }
164 }
165 pub fn is_unit(&self) -> bool {
166 match self {
167 VariantData::Unit => true,
168 _ => false,
169 }
170 }
171}
172
146#[derive(Debug, Clone, PartialEq, Eq, Hash)] 173#[derive(Debug, Clone, PartialEq, Eq, Hash)]
147pub struct Struct { 174pub struct Struct {
148 pub(crate) def_id: DefId, 175 pub(crate) def_id: DefId,