Trait textwrap::WordSplitter [] [src]

pub trait WordSplitter {
    fn split<'w>(&self, word: &'w str) -> Vec<(&'w str, &'w str, &'w str)>;
}

An interface for splitting words.

When the wrap method will try to fit text into a line, it will eventually find a word that it too large the current text width. It will then call the currently configured WordSplitter to have it attempt to split the word into smaller parts. This trait describes that functionality via the split method.

If the textwrap crate has been compiled with the hyphenation feature enabled, you will find an implementation of WordSplitter by the hyphenation::language::Corpus struct. Use this struct for language-aware hyphenation. See the hyphenation documentation for details.

Required Methods

Return all possible splits of word. Each split is a triple with a head, a hyphen, and a tail where head + &hyphen + &tail == word. The hyphen can be empty if there is already a hyphen in the head.

The splits should go from smallest to longest and should include no split at all. So the word "technology" could be split into

vec![("tech", "-", "nology"),
     ("technol", "-", "ogy"),
     ("technolo", "-", "gy"),
     ("technology", "", "")];

Implementors