Struct textwrap::core::Word[][src]

pub struct Word<'a> {
    pub word: &'a str,
    pub whitespace: &'a str,
    pub penalty: &'a str,
    // some fields omitted
}
Expand description

A piece of wrappable text, including any trailing whitespace.

A Word is an example of a Fragment, so it has a width, trailing whitespace, and potentially a penalty item.

Fields

word: &'a str

Word content.

whitespace: &'a str

Whitespace to insert if the word does not fall at the end of a line.

penalty: &'a str

Penalty string to insert if the word falls at the end of a line.

Implementations

Construct a Word from a string.

A trailing stretch of ' ' is automatically taken to be the whitespace part of the word.

Break this word into smaller words with a width of at most line_width. The whitespace and penalty from this Word is added to the last piece.

Examples

use textwrap::core::Word;
assert_eq!(
    Word::from("Hello!  ").break_apart(3).collect::<Vec<_>>(),
    vec![Word::from("Hel"), Word::from("lo!  ")]
);

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

The resulting type after dereferencing.

Dereferences the value.

Displayed width of word represented by this fragment.

Displayed width of the whitespace that must follow the word when the word is not at the end of a line. Read more

Displayed width of the penalty that must be inserted if the word falls at the end of a line. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.