Skip to main content

wrap_text_words

Function wrap_text_words 

Source
pub fn wrap_text_words(
    text: &str,
    first_width: usize,
    continuation_width: usize,
) -> Vec<String>
Expand description

Word-wrap text into lines, allowing first_width chars on the first line and continuation_width chars on subsequent lines. Wrapping prefers whitespace boundaries and is UTF-8 safe (widths count chars, not bytes).

Returns an empty vec for blank input. Words longer than the width are split at the width boundary rather than overflowing.

let lines = wrap_text_words("the quick brown fox", 9, 9);
assert_eq!(lines, vec!["the quick", "brown fox"]);
assert!(wrap_text_words("   ", 5, 5).is_empty());