Function textwrap::wrap

source ·
pub fn wrap(s: &str, width: usize) -> Vec<Cow<'_, str>>
Expand description

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

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 wrap many strings, then it is suggested to create a Wrapper and call its wrap method.

The result is a vector of strings. Use wrap_iter if you need an iterator version.


use textwrap::wrap;

assert_eq!(wrap("Concurrency without data races.", 15),
                "without data",

assert_eq!(wrap("Concurrency without data races.", 20),
           vec!["Concurrency without",
                "data races."]);