Function textwrap::word_splitters::split_words[][src]

pub fn split_words<'a, I, WordSplit>(
    words: I,
    word_splitter: &'a WordSplit
) -> impl Iterator<Item = Word<'a>> where
    I: IntoIterator<Item = Word<'a>>,
    WordSplit: WordSplitter
Expand description

Split words into smaller words according to the split points given by word_splitter.

Note that we split all words, regardless of their length. This is to more cleanly separate the business of splitting (including automatic hyphenation) from the business of word wrapping.

Examples

use textwrap::core::Word;
use textwrap::word_splitters::{split_words, NoHyphenation, HyphenSplitter};

assert_eq!(
    split_words(vec![Word::from("foo-bar")], &HyphenSplitter).collect::<Vec<_>>(),
    vec![Word::from("foo-"), Word::from("bar")]
);

// The NoHyphenation splitter ignores the '-':
assert_eq!(
    split_words(vec![Word::from("foo-bar")], &NoHyphenation).collect::<Vec<_>>(),
    vec![Word::from("foo-bar")]
);