1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
use crate::common::{Identifier, Span};
use leo_grammar::common::VariableName as GrammarVariableName;
use serde::{Deserialize, Serialize};
use std::fmt;
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct VariableName {
pub mutable: bool,
pub identifier: Identifier,
pub span: Span,
}
impl<'ast> From<GrammarVariableName<'ast>> for VariableName {
fn from(name: GrammarVariableName<'ast>) -> Self {
Self {
mutable: name.mutable.is_some(),
identifier: Identifier::from(name.identifier),
span: Span::from(name.span),
}
}
}
impl fmt::Display for VariableName {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
if self.mutable {
write!(f, "mut ")?;
}
write!(f, "{}", self.identifier)
}
}