Skip to content

Commit

Permalink
Merge pull request #299 from mgeisler/refill-examples
Browse files Browse the repository at this point in the history
Add more refill examples
  • Loading branch information
mgeisler authored Feb 28, 2021
2 parents c0a0db1 + 9425d4f commit 15816b8
Showing 1 changed file with 33 additions and 5 deletions.
38 changes: 33 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -728,16 +728,44 @@ pub fn unfill<'a>(text: &'a str) -> (String, Options<'a, HyphenSplitter>) {
/// ```
/// use textwrap::refill;
///
/// // Some loosely wrapped text. The "> " prefix is recognized automatically.
/// let text = "\
/// > Memory safety without
/// > garbage collection.
/// > Memory
/// > safety without garbage
/// > collection.
/// ";
/// assert_eq!(refill(text, 15), "\
///
/// assert_eq!(refill(text, 20), "\
/// > Memory safety
/// > without
/// > garbage
/// > 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.
/// ");
/// ```
pub fn refill<'a, S, Opt>(filled_text: &str, new_width_or_options: Opt) -> String
where
S: WordSplitter,
Expand Down

0 comments on commit 15816b8

Please sign in to comment.