[−][src]Trait binjs_meta::util::Reindentable
A string or string-like construction that can be reindented.
Required methods
fn reindent(&self, prefix: &str) -> String
Remove leading whitespace, replace it with prefix.
If self spans more than one line, the leading whitespace
is computed from the first line and extracted from all lines
and prefix is added to all lines.
use binjs_meta::util::Reindentable; assert_eq!(&"abc".reindent(" "), " abc"); assert_eq!(&" def".reindent(" "), " def"); assert_eq!(&" ghi".reindent(" "), " ghi"); assert_eq!(&" jkl\n mno".reindent(" "), " jkl\n mno");
fn fit(&self, prefix: &str, width: usize) -> String
Remove leading whitespace, replace it with prefix,
ensure that the text fits within width columns.
If self spans more than one line, the leading whitespace
is computed from the first line and extracted from all lines.
and prefix is added to all lines.
If the result goes past width columns, self is split
into several lines to try and fit within width columns.
use binjs_meta::util::Reindentable; assert_eq!(&"abc".fit("// ", 30), "// abc"); assert_eq!(&" def".fit("// ", 30), "// def"); assert_eq!(&" ghi".fit("// ", 30), "// ghi"); assert_eq!(&" jkl\n mno".fit("// ", 30), "// jkl\n// mno"); assert_eq!(&"abc def ghi".fit("// ", 8), "// abc\n// def\n// ghi"); assert_eq!(&"abc def ghi".fit("// ", 5), "// abc\n// def\n// ghi");