pub trait RemoveDuplicateSpaces { fn remove_duplicate_spaces(self) -> Self; } pub trait Indent { fn indent(self, number: usize) -> Self; } impl RemoveDuplicateSpaces for String { fn remove_duplicate_spaces(self) -> Self { let mut replaced = self; while replaced.contains(" ") { replaced = replaced.replace(" ", " "); } replaced } } impl Indent for String { fn indent(self, number: usize) -> Self { let mut padding = "".to_string(); for _ in 0..number { padding = format!(" {}", padding); } let lines: Vec = self.lines().map(|l| format!("{}{}", padding, l)).collect(); lines.join("\n") } }