use std::fmt;
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct Explained {
pub settings: Vec<Line>,
pub notes: Vec<String>,
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct Line {
pub path: String,
pub value: String,
pub from: String,
pub over: Vec<String>,
}
impl fmt::Display for Explained {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let width = |column: fn(&Line) -> &str| self.settings.iter().map(|line| column(line).len()).max().unwrap_or(0);
let (path, value, from) = (width(|line| &line.path), width(|line| &line.value), width(|line| &line.from));
for line in &self.settings {
let over = if line.over.is_empty() { String::new() } else { format!(" over {}", line.over.join(", ")) };
let row = format!("{:path$} {:value$} {:from$}{over}", line.path, line.value, line.from);
writeln!(f, "{}", row.trim_end())?;
}
for note in &self.notes {
writeln!(f, "{note}")?;
}
Ok(())
}
}