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