pub fn fill<'a, Opt>(text: &str, width_or_options: Opt) -> String
Expand description
Fill a line of text at a given width.
The result is a String
, complete with newlines between each
line. Use wrap()
if you need access to the individual lines.
The easiest way to use this function is to pass an integer for
width_or_options
:
use textwrap::fill;
assert_eq!(
fill("Memory safety without garbage collection.", 15),
"Memory safety\nwithout garbage\ncollection."
);
If you need to customize the wrapping, you can pass an Options
instead of an usize
:
use textwrap::{fill, Options};
let options = Options::new(15)
.initial_indent("- ")
.subsequent_indent(" ");
assert_eq!(
fill("Memory safety without garbage collection.", &options),
"- Memory safety\n without\n garbage\n collection."
);