Trait textwrap::word_separators::WordSeparator[][src]

pub trait WordSeparator: WordSeparatorClone + Debug {
    fn find_words<'a>(
        &self,
        line: &'a str
    ) -> Box<dyn Iterator<Item = Word<'a>> + 'a>; }
Expand description

Describes where words occur in a line of text.

The simplest approach is say that words are separated by one or more ASCII spaces (' '). This works for Western languages without emojis. A more complex approach is to use the Unicode line breaking algorithm, which finds break points in non-ASCII text.

The line breaks occur between words, please see the WordSplitter trait for options of how to handle hyphenation of individual words.

Examples

use textwrap::core::Word;
use textwrap::word_separators::{WordSeparator, AsciiSpace};

let words = AsciiSpace.find_words("Hello World!").collect::<Vec<_>>();
assert_eq!(words, vec![Word::from("Hello "), Word::from("World!")]);

Required methods

Find all words in line.

Implementations on Foreign Types

Implementors