2017-11-16 23:30:08 -08:00
|
|
|
use common::*;
|
|
|
|
|
|
|
|
#[derive(PartialEq, Debug)]
|
|
|
|
pub struct Parameter<'a> {
|
2018-12-08 14:29:41 -08:00
|
|
|
pub default: Option<String>,
|
|
|
|
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 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 {
|
2018-12-08 14:29:41 -08:00
|
|
|
let escaped = default
|
|
|
|
.chars()
|
|
|
|
.flat_map(char::escape_default)
|
|
|
|
.collect::<String>();;
|
2017-11-16 23:30:08 -08:00
|
|
|
write!(f, r#"='{}'"#, color.string().paint(&escaped))?;
|
|
|
|
}
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|