Skip to main content

wrap_str

Function wrap_str 

Source
pub fn wrap_str(text: &str, max_width: u16) -> Vec<Cow<'_, str>>
Expand description

Word-wraps plain text to max_width columns, returning the broken-apart rows.

This runs the same greedy, grapheme-cluster-aware wrap pass as wrap (breaking on ASCII space, honoring hard \ns, force-breaking an overlong word at the column boundary), for callers that just have a plain string and would otherwise hand-roll a wrap loop to get it. Reach for wrap instead when the text carries per-Span Style: text: &str converts to a plain Line via .into(), so wrap(&text.into(), w) covers that case without constructing spans by hand.

Each row is grapheme-rejoined during wrapping, so this always returns Cow::Owned; the Cow return type is kept so a row that turns out not to need wrapping can borrow text directly if a future revision adds that fast path.

ยงExamples

use retroglyph_core::layout::wrap_str;

let rows = wrap_str("hello world", 7);
assert_eq!(rows, vec!["hello", "world"]);