[][src]Function textwrap::fill

pub fn fill<'a, S, Opt>(text: &str, options: Opt) -> String where
    S: WordSplitter,
    Opt: Into<Options<'a, S>>, 

Fill a line of text at width characters.

The result is a String, complete with newlines between each line. Use the wrap function if you need access to the individual lines.

The easiest way to use this function is to pass an integer for options:

use textwrap::fill;

assert_eq!(
    fill("Memory safety without garbage collection.", 15),
    "Memory safety\nwithout garbage\ncollection."
);

If you need to customize the wrapping, you can pass an Options instead of an usize:

use textwrap::{fill, Options};

let options = Options::new(15)
    .initial_indent("- ")
    .subsequent_indent("  ");
assert_eq!(
    fill("Memory safety without garbage collection.", &options),
    "- Memory safety\n  without\n  garbage\n  collection."
);