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