sway_core/language/parsed/declaration/
constant.rs

1use crate::{
2    engine_threading::{
3        DebugWithEngines, EqWithEngines, PartialEqWithEngines, PartialEqWithEnginesContext,
4    },
5    language::{parsed::Expression, Visibility},
6    transform, Engines, GenericArgument,
7};
8use sway_types::{Ident, Named, Span, Spanned};
9
10#[derive(Debug, Clone)]
11pub struct ConstantDeclaration {
12    pub name: Ident,
13    pub attributes: transform::Attributes,
14    pub type_ascription: GenericArgument,
15    pub value: Option<Expression>,
16    pub visibility: Visibility,
17    pub span: Span,
18}
19
20impl EqWithEngines for ConstantDeclaration {}
21impl PartialEqWithEngines for ConstantDeclaration {
22    fn eq(&self, other: &Self, ctx: &PartialEqWithEnginesContext) -> bool {
23        self.name == other.name
24            && self.attributes == other.attributes
25            && self.type_ascription.eq(&other.type_ascription, ctx)
26            && self.value.eq(&other.value, ctx)
27            && self.visibility == other.visibility
28            && self.span == other.span
29    }
30}
31
32impl Named for ConstantDeclaration {
33    fn name(&self) -> &sway_types::BaseIdent {
34        &self.name
35    }
36}
37
38impl Spanned for ConstantDeclaration {
39    fn span(&self) -> sway_types::Span {
40        self.span.clone()
41    }
42}
43
44impl DebugWithEngines for ConstantDeclaration {
45    fn fmt(&self, f: &mut std::fmt::Formatter<'_>, _engines: &Engines) -> std::fmt::Result {
46        f.write_fmt(format_args!("{}", self.name))
47    }
48}