-
Notifications
You must be signed in to change notification settings - Fork 499
/
parameter.rs
30 lines (28 loc) · 879 Bytes
/
parameter.rs
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
use super::*;
/// A single function parameter
#[derive(PartialEq, Debug, Clone, Serialize)]
pub(crate) struct Parameter<'src> {
/// An optional default expression
pub(crate) default: Option<Expression<'src>>,
/// Export parameter as environment variable
pub(crate) export: bool,
/// The kind of parameter
pub(crate) kind: ParameterKind,
/// The parameter name
pub(crate) name: Name<'src>,
}
impl ColorDisplay for Parameter<'_> {
fn fmt(&self, f: &mut Formatter, color: Color) -> fmt::Result {
if let Some(prefix) = self.kind.prefix() {
write!(f, "{}", color.annotation().paint(prefix))?;
}
if self.export {
write!(f, "$")?;
}
write!(f, "{}", color.parameter().paint(self.name.lexeme()))?;
if let Some(ref default) = self.default {
write!(f, "={}", color.string().paint(&default.to_string()))?;
}
Ok(())
}
}