array_tool::string

Trait WordWrap

Source
pub trait WordWrap {
    // Required method
    fn word_wrap(&self, width: usize) -> String;
}
Expand description

Word wrapping

Required Methods§

Source

fn word_wrap(&self, width: usize) -> String

White space is treated as valid content and new lines will only be swapped in for the last white space character at the end of the given width. White space may reach beyond the width you’ve provided. You will need to trim end of lines in your own output (e.g. splitting string at each new line and printing the line with trim_right). Or just trust that lines that are beyond the width are just white space and only print the width - ignoring tailing white space.

§Example
use array_tool::string::WordWrap;

"asd asdf asd".word_wrap(8);
§Output
"asd asdf\nasd"

Implementations on Foreign Types§

Source§

impl WordWrap for &'static str

Source§

fn word_wrap(&self, width: usize) -> String

Implementors§