just/src/parameter.rs

24 lines
598 B
Rust
Raw Normal View History

use crate::common::*;
2017-11-16 23:30:08 -08:00
#[derive(PartialEq, Debug)]
pub struct Parameter<'a> {
pub default: Option<Expression<'a>>,
pub name: &'a str,
pub token: Token<'a>,
2017-11-16 23:30:08 -08:00
pub variadic: bool,
}
impl<'a> Display for Parameter<'a> {
fn fmt(&self, f: &mut Formatter) -> Result<(), fmt::Error> {
2017-11-16 23:30:08 -08:00
let color = Color::fmt(f);
if self.variadic {
write!(f, "{}", color.annotation().paint("+"))?;
}
write!(f, "{}", color.parameter().paint(self.name))?;
if let Some(ref default) = self.default {
write!(f, "={}", color.string().paint(&default.to_string()))?;
2017-11-16 23:30:08 -08:00
}
Ok(())
}
}