stern4rust/reporting/
column_widths.rs1use crate::reporting::offence::Offence;
6
7pub struct ColumnWidths {
14 pub file: usize,
15 pub line: usize,
16 pub rule: usize,
17 pub description: usize,
18}
19
20impl ColumnWidths {
21 pub fn of(offences: &[Offence]) -> Self {
22 Self {
23 file: Self::widest(offences.iter().map(|offence| offence.file.len()), "file"),
24 line: Self::widest(
25 offences
26 .iter()
27 .map(|offence| offence.line.to_string().len()),
28 "line",
29 ),
30 rule: Self::widest(offences.iter().map(|offence| offence.rule.len()), "rule"),
31 description: Self::widest(
32 offences.iter().map(|offence| offence.description.len()),
33 "offence",
34 ),
35 }
36 }
37
38 fn widest<I: Iterator<Item = usize>>(lengths: I, heading: &str) -> usize {
39 lengths.max().unwrap_or(0).max(heading.len())
40 }
41}