Function textwrap::fill [] [src]

pub fn fill(s: &str, width: usize) -> String

Fill a line of text at width characters. Strings are wrapped based on their displayed width, not their size in bytes.

The result is a string with newlines between each line. Use wrap if you need access to the individual lines or wrap_iter for its iterator counterpart.

use textwrap::fill;

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

This function creates a Wrapper on the fly with default settings. If you need to set a language corpus for automatic hyphenation, or need to fill many strings, then it is suggested to create a Wrapper and call its fill method.