Skip to main content

word_wrap

Function word_wrap 

Source
pub fn word_wrap(value: impl Display, width: usize) -> String
Expand description

Breaks lines longer than width characters at spaces (Rails’ word_wrap).

Words longer than width stay whole; existing line breaks are kept. In HTML, show the breaks with |linebreaksbr or in a <pre>.

§Examples

assert_eq!(ocre::helpers::word_wrap("Once upon a time", 8), "Once\nupon a\ntime");