[][src]Trait textwrap::wrap_algorithms::WrapAlgorithm

pub trait WrapAlgorithm: WrapAlgorithmClone + Debug {
    fn wrap<'a, 'b>(
        &self,
        words: &'b [Word<'a>],
        line_widths: &'b [usize]
    ) -> Vec<&'b [Word<'a>]>; }

Describes how to wrap words into lines.

The simplest approach is to wrap words one word at a time. This is implemented by FirstFit. If the smawk Cargo feature is enabled, a more complex algorithm is available, implemented by OptimalFit, which will look at an entire paragraph at a time in order to find optimal line breaks.

Required methods

fn wrap<'a, 'b>(
    &self,
    words: &'b [Word<'a>],
    line_widths: &'b [usize]
) -> Vec<&'b [Word<'a>]>

Wrap words according to line widths.

The line_widths slice gives the target line width for each line (the last slice element is repeated as necessary). This can be used to implement hanging indentation.

Please see the implementors of the trait for examples.

Loading content...

Implementations on Foreign Types

impl WrapAlgorithm for Box<dyn WrapAlgorithm>[src]

Loading content...

Implementors

impl WrapAlgorithm for FirstFit[src]

impl WrapAlgorithm for OptimalFit[src]

Loading content...