[][src]Trait textwrap::WordSplitter

pub trait WordSplitter: Debug {
    pub fn split_points(&self, word: &str) -> Vec<usize>;
}

The WordSplitter trait describes where words can be split.

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

Required methods

pub fn split_points(&self, word: &str) -> Vec<usize>[src]

Return all possible indices where word can be split.

The indices returned must be in range 0..word.len(). They should point to the index after the split point, i.e., after - if splitting on hyphens. This way, word.split_at(idx) will break the word into two well-formed pieces.

Examples

use textwrap::{HyphenSplitter, NoHyphenation, WordSplitter};
assert_eq!(NoHyphenation.split_points("cannot-be-split"), vec![]);
assert_eq!(HyphenSplitter.split_points("can-be-split"), vec![4, 7]);
Loading content...

Implementations on Foreign Types

impl WordSplitter for Box<dyn WordSplitter>[src]

impl<T: ?Sized + WordSplitter, '_> WordSplitter for &'_ T[src]

impl WordSplitter for Standard[src]

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

Note: Only available when the hyphenation feature is enabled.

Loading content...

Implementors

impl WordSplitter for HyphenSplitter[src]

HyphenSplitter is the default WordSplitter used by Options::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 into "--" and "foo-bar".

impl WordSplitter for NoHyphenation[src]

NoHyphenation implements WordSplitter by not splitting the word at all.

Loading content...