Function textwrap::refill[][src]

pub fn refill<'a, WrapAlgo, WordSep, WordSplit, Opt>(
    filled_text: &str,
    new_width_or_options: Opt
) -> String where
    WrapAlgo: WrapAlgorithm,
    WordSep: WordSeparator,
    WordSplit: WordSplitter,
    Opt: Into<Options<'a, WrapAlgo, WordSep, WordSplit>>, 
Expand description

Refill a paragraph of wrapped text with a new width.

This function will first use the unfill function to remove newlines from the text. Afterwards the text is filled again using the fill function.

The new_width_or_options argument specify the new width and can specify other options as well — except for Options::initial_indent and Options::subsequent_indent, which are deduced from filled_text.

Examples

use textwrap::refill;

// Some loosely wrapped text. The "> " prefix is recognized automatically.
let text = "\
> Memory
> safety without garbage
> collection.
";

assert_eq!(refill(text, 20), "\
> Memory safety
> without garbage
> collection.
");

assert_eq!(refill(text, 40), "\
> Memory safety without garbage
> collection.
");

assert_eq!(refill(text, 60), "\
> Memory safety without garbage collection.
");

You can also reshape bullet points:

use textwrap::refill;

let text = "\
- This is my
  list item.
";

assert_eq!(refill(text, 20), "\
- This is my list
  item.
");