just/src/parameter.rs
2017-11-18 01:44:59 -08:00

25 lines
678 B
Rust

use common::*;
#[derive(PartialEq, Debug)]
pub struct Parameter<'a> {
pub default: Option<String>,
pub name: &'a str,
pub token: Token<'a>,
pub variadic: bool,
}
impl<'a> Display for Parameter<'a> {
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
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 {
let escaped = default.chars().flat_map(char::escape_default).collect::<String>();;
write!(f, r#"='{}'"#, color.string().paint(&escaped))?;
}
Ok(())
}
}