Trait textwrap::WordSplitter [−][src]
Expand description
An interface for splitting words.
When the wrap_iter 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
HyphenSplitter is the default WordSplitter used by
Wrapper::new. It will split words on any existing hyphens in the
word.
It will only use hyphens that are surrounded by alphanumeric characters, which prevents a word like “–foo-bar” from being split on the first or second hyphen.
NoHyphenation implements WordSplitter by not splitting the
word at all.
