[][src]Trait textwrap::WordSplitter

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_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

fn split<'w>(&self, word: &'w str) -> Vec<(&'w str, &'w str, &'w str)>

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", "", "")];
Loading content...

Implementations on Foreign Types

impl WordSplitter for Standard[src]

A hyphenation dictionary can be used to do language-specific hyphenation using patterns from the hyphenation crate.

Loading content...

Implementors

impl WordSplitter for HyphenSplitter[src]

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.

impl WordSplitter for NoHyphenation[src]

NoHyphenation implements WordSplitter by not splitting the word at all.

Loading content...