From 9425d4f00e888c6c4cf38fb0df06278120d93b7e Mon Sep 17 00:00:00 2001 From: Martin Geisler Date: Sun, 28 Feb 2021 12:52:02 +0100 Subject: [PATCH] Add more refill examples --- src/lib.rs | 38 +++++++++++++++++++++++++++++++++----- 1 file changed, 33 insertions(+), 5 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index ee6d5d85..03fc63e5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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,