pub trait Indentable { fn indent(&self, spaces: T) -> String; } impl Indentable for &str { fn indent(&self, spaces: usize) -> String { let indent_str = " ".repeat(spaces); self.lines() .map(|line| format!("{}{}", indent_str, line)) .collect::>() .join("\n") } } impl Indentable> for String { fn indent(&self, spaces: Option) -> String { self.as_str().indent(spaces.unwrap_or(0)) } } impl Indentable for String { fn indent(&self, spaces: usize) -> String { self.as_str().indent(spaces) } } impl Indentable> for &str { fn indent(&self, spaces: Option) -> String { self.indent(spaces.unwrap_or(0)) } }