sway_core/language/parsed/declaration/
variable.rs

1use sway_types::{Named, Spanned};
2
3use crate::{
4    engine_threading::{EqWithEngines, PartialEqWithEngines, PartialEqWithEnginesContext},
5    language::parsed::Expression,
6    GenericArgument, Ident,
7};
8
9#[derive(Debug, Clone)]
10pub struct VariableDeclaration {
11    pub name: Ident,
12    pub type_ascription: GenericArgument,
13    pub body: Expression, // will be codeblock variant
14    pub is_mutable: bool,
15}
16
17impl EqWithEngines for VariableDeclaration {}
18impl PartialEqWithEngines for VariableDeclaration {
19    fn eq(&self, other: &Self, ctx: &PartialEqWithEnginesContext) -> bool {
20        self.name == other.name
21            && self.type_ascription.eq(&other.type_ascription, ctx)
22            && self.body.eq(&other.body, ctx)
23            && self.is_mutable == other.is_mutable
24    }
25}
26
27impl Named for VariableDeclaration {
28    fn name(&self) -> &sway_types::BaseIdent {
29        &self.name
30    }
31}
32
33impl Spanned for VariableDeclaration {
34    fn span(&self) -> sway_types::Span {
35        self.name.span()
36    }
37}