rujag/
tools.rs

1pub trait RemoveDuplicateSpaces {
2    fn remove_duplicate_spaces(self) -> Self;
3}
4
5pub trait Indent {
6    fn indent(self, number: usize) -> Self;
7}
8
9impl RemoveDuplicateSpaces for String {
10    fn remove_duplicate_spaces(self) -> Self {
11        let mut replaced = self;
12        while replaced.contains("  ") {
13            replaced = replaced.replace("  ", " ");
14        }
15        replaced
16    }
17}
18
19impl Indent for String {
20    fn indent(self, number: usize) -> Self {
21        let mut padding = "".to_string();
22        for _ in 0..number {
23            padding = format!(" {}", padding);
24        }
25        let lines: Vec<String> = self.lines().map(|l| format!("{}{}", padding, l)).collect();
26        lines.join("\n")
27    }
28}