Function textwrap::indent [] [src]

pub fn indent(s: &str, prefix: &str) -> String

Add prefix to each non-empty line.

use textwrap::indent;

assert_eq!(indent("Foo\nBar\n", "  "), "  Foo\n  Bar\n");

Empty lines (lines consisting only of whitespace) are not indented and the whitespace is replaced by a single newline (\n):

use textwrap::indent;

assert_eq!(indent("Foo\n\nBar\n  \t  \nBaz\n", "  "),
           "  Foo\n\n  Bar\n\n  Baz\n");

Leading and trailing whitespace on non-empty lines is kept unchanged:

use textwrap::indent;

assert_eq!(indent(" \t  Foo   ", "  "), "   \t  Foo   \n");