pub fn refill<'a, Opt>(filled_text: &str, new_width_or_options: Opt) -> String
Expand description
Refill a paragraph of wrapped text with a new width.
This function will first use unfill()
to remove newlines from
the text. Afterwards the text is filled again using fill()
.
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.
");