Enum textwrap::WordSeparator
source · pub enum WordSeparator {
AsciiSpace,
Custom(fn(line: &str) -> Box<dyn Iterator<Item = Word<'_>> + '_>),
}Expand description
Describes where words occur in a line of text.
The simplest approach is say that words are separated by one or
more ASCII spaces (' '). This works for Western languages
without emojis. A more complex approach is to use the Unicode line
breaking algorithm, which finds break points in non-ASCII text.
The line breaks occur between words, please see
WordSplitter for options of how to handle
hyphenation of individual words.
§Examples
use textwrap::core::Word;
use textwrap::WordSeparator::AsciiSpace;
let words = AsciiSpace.find_words("Hello World!").collect::<Vec<_>>();
assert_eq!(words, vec![Word::from("Hello "), Word::from("World!")]);Variants§
AsciiSpace
Find words by splitting on runs of ' ' characters.
§Examples
use textwrap::core::Word;
use textwrap::WordSeparator::AsciiSpace;
let words = AsciiSpace.find_words("Hello World!").collect::<Vec<_>>();
assert_eq!(words, vec![Word::from("Hello "),
Word::from("World!")]);Custom(fn(line: &str) -> Box<dyn Iterator<Item = Word<'_>> + '_>)
Find words using a custom word separator
Implementations§
source§impl WordSeparator
impl WordSeparator
sourcepub const fn new() -> Self
pub const fn new() -> Self
Create a new word separator.
The best available algorithm is used by default, i.e.,
[WordSeparator::UnicodeBreakProperties] if available,
otherwise WordSeparator::AsciiSpace.
Trait Implementations§
source§impl Clone for WordSeparator
impl Clone for WordSeparator
source§fn clone(&self) -> WordSeparator
fn clone(&self) -> WordSeparator
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moresource§impl Debug for WordSeparator
impl Debug for WordSeparator
source§impl PartialEq for WordSeparator
impl PartialEq for WordSeparator
source§fn eq(&self, other: &Self) -> bool
fn eq(&self, other: &Self) -> bool
Compare two word separators.
use textwrap::WordSeparator;
assert_eq!(WordSeparator::AsciiSpace, WordSeparator::AsciiSpace);
#[cfg(feature = "unicode-linebreak")] {
assert_eq!(WordSeparator::UnicodeBreakProperties,
WordSeparator::UnicodeBreakProperties);
}Note that WordSeparator::Custom values never compare equal:
use textwrap::WordSeparator;
use textwrap::core::Word;
fn word_separator(line: &str) -> Box<dyn Iterator<Item = Word<'_>> + '_> {
Box::new(line.split_inclusive(' ').map(Word::from))
}
assert_ne!(WordSeparator::Custom(word_separator),
WordSeparator::Custom(word_separator));impl Copy for WordSeparator
Auto Trait Implementations§
impl Freeze for WordSeparator
impl RefUnwindSafe for WordSeparator
impl Send for WordSeparator
impl Sync for WordSeparator
impl Unpin for WordSeparator
impl UnwindSafe for WordSeparator
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit)source§impl<T> CloneToUninit for Twhere
T: Copy,
impl<T> CloneToUninit for Twhere
T: Copy,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit)