Trait textwrap::core::Fragment

source ·
pub trait Fragment: Debug {
    // Required methods
    fn width(&self) -> f64;
    fn whitespace_width(&self) -> f64;
    fn penalty_width(&self) -> f64;
}
Expand description

A (text) fragment denotes the unit which we wrap into lines.

Fragments represent an abstract word plus the whitespace following the word. In case the word falls at the end of the line, the whitespace is dropped and a so-called penalty is inserted instead (typically "-" if the word was hyphenated).

For wrapping purposes, the precise content of the word, the whitespace, and the penalty is irrelevant. All we need to know is the displayed width of each part, which this trait provides.

Required Methods§

source

fn width(&self) -> f64

Displayed width of word represented by this fragment.

source

fn whitespace_width(&self) -> f64

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

source

fn penalty_width(&self) -> f64

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

Implementors§

source§

impl Fragment for Word<'_>