Struct textwrap::Wrapper
[−]
[src]
pub struct Wrapper { /* fields omitted */ }
A Wrapper holds settings for wrapping text.
Methods
impl Wrapper
[src]
fn new(width: usize) -> Wrapper
Create a new Wrapper for wrapping at the specified width.
fn fill(&self, s: &str) -> String
Fill a line of text at self.width
bytes.
The result is a string with newlines between each line. Use
the wrap
method if you need access to the individual lines.
use textwrap::Wrapper; let wrapper = Wrapper::new(15); assert_eq!(wrapper.fill("Memory safety without garbage collection."), "Memory safety\nwithout garbage\ncollection.");
fn wrap(&self, s: &str) -> Vec<String>
Wrap a line of text at self.width
bytes and return a vector
of lines.
use textwrap::Wrapper; let wrap15 = Wrapper::new(15); assert_eq!(wrap15.wrap("Concurrency without data races."), vec!["Concurrency", "without data", "races."]); let wrap20 = Wrapper::new(20); assert_eq!(wrap20.wrap("Concurrency without data races."), vec!["Concurrency without", "data races."]);