just/src/parameter.rs

31 lines
898 B
Rust
Raw Normal View History

use super::*;
2017-11-16 23:30:08 -08:00
/// A single function parameter
2021-11-17 00:07:48 -08:00
#[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,
2021-11-17 00:07:48 -08:00
/// The kind of parameter
pub(crate) kind: ParameterKind,
/// The parameter name
pub(crate) name: Name<'src>,
2017-11-16 23:30:08 -08:00
}
impl<'src> ColorDisplay for Parameter<'src> {
fn fmt(&self, f: &mut Formatter, color: Color) -> Result<(), fmt::Error> {
if let Some(prefix) = self.kind.prefix() {
write!(f, "{}", color.annotation().paint(prefix))?;
2017-11-16 23:30:08 -08:00
}
if self.export {
write!(f, "$")?;
}
write!(f, "{}", color.parameter().paint(self.name.lexeme()))?;
2017-11-16 23:30:08 -08:00
if let Some(ref default) = self.default {
write!(f, "={}", color.string().paint(&default.to_string()))?;
2017-11-16 23:30:08 -08:00
}
Ok(())
}
}