aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/adt.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir/src/adt.rs')
-rw-r--r--crates/ra_hir/src/adt.rs30
1 files changed, 3 insertions, 27 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] {