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