1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
pub struct Comment<'a> {
lines: &'static [&'static str],
prefix: &'a str,
}
impl<'a> Comment<'a> {
pub fn new(lines: &'static [&'static str], prefix: &'a str) -> Self {
Self { lines, prefix }
}
pub fn to_string(&self, offset: usize) -> String {
self.lines
.iter()
.map(|line| {
let mut line = line.to_string();
if !line.is_empty() {
line = format!(" {}", line);
}
format!(
"{spaces}{prefix}{line}",
spaces = " ".repeat(offset),
prefix = self.prefix,
line = line
)
})
.collect::<Vec<_>>()
.join("\n")
}
}