sway_core/language/parsed/declaration/
struct.rs1use crate::{
2 engine_threading::{EqWithEngines, PartialEqWithEngines, PartialEqWithEnginesContext},
3 language::Visibility,
4 transform,
5 type_system::TypeParameter,
6 GenericArgument,
7};
8use sway_types::{ident::Ident, span::Span, Named, Spanned};
9
10#[derive(Debug, Clone)]
11pub struct StructDeclaration {
12 pub name: Ident,
13 pub attributes: transform::Attributes,
14 pub fields: Vec<StructField>,
15 pub type_parameters: Vec<TypeParameter>,
16 pub visibility: Visibility,
17 pub(crate) span: Span,
18}
19
20impl EqWithEngines for StructDeclaration {}
21impl PartialEqWithEngines for StructDeclaration {
22 fn eq(&self, other: &Self, ctx: &PartialEqWithEnginesContext) -> bool {
23 self.name == other.name
24 && self.type_parameters.eq(&other.type_parameters, ctx)
25 && self.attributes == other.attributes
26 && self.fields.eq(&other.fields, ctx)
27 && self.type_parameters.eq(&other.type_parameters, ctx)
28 && self.visibility == other.visibility
29 && self.span == other.span
30 }
31}
32
33impl Named for StructDeclaration {
34 fn name(&self) -> &sway_types::BaseIdent {
35 &self.name
36 }
37}
38
39impl Spanned for StructDeclaration {
40 fn span(&self) -> sway_types::Span {
41 self.span.clone()
42 }
43}
44
45#[derive(Debug, Clone)]
46pub struct StructField {
47 pub visibility: Visibility,
48 pub name: Ident,
49 pub attributes: transform::Attributes,
50 pub(crate) span: Span,
51 pub type_argument: GenericArgument,
52}
53
54impl EqWithEngines for StructField {}
55impl PartialEqWithEngines for StructField {
56 fn eq(&self, other: &Self, ctx: &PartialEqWithEnginesContext) -> bool {
57 self.visibility == other.visibility
58 && self.name == other.name
59 && self.attributes == other.attributes
60 && self.span == other.span
61 && self.type_argument.eq(&other.type_argument, ctx)
62 }
63}