From bb55f29e507f440b89d55065f5223398cf0347a1 Mon Sep 17 00:00:00 2001 From: Martin Geisler Date: Sat, 14 Nov 2020 21:57:16 +0100 Subject: [PATCH 1/6] Simplify From implementation for Options --- src/lib.rs | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 65076f4b..bd691f7e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -139,13 +139,7 @@ impl<'a, S> From<&'a Options<'a, S>> for Options<'a, &'a S> { impl<'a> From for Options<'a, HyphenSplitter> { fn from(width: usize) -> Self { - Self { - width, - initial_indent: "", - subsequent_indent: "", - break_words: true, - splitter: HyphenSplitter, - } + Options::new(width) } } From eb8eda77ec4160b94698cd9b77e99e6f1111e179 Mon Sep 17 00:00:00 2001 From: Martin Geisler Date: Sat, 14 Nov 2020 21:58:02 +0100 Subject: [PATCH 2/6] Simplify use statements --- src/core.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/core.rs b/src/core.rs index dfcc3cfa..60d0153f 100644 --- a/src/core.rs +++ b/src/core.rs @@ -4,7 +4,7 @@ //! advanced wrapping functionality when the `wrap` and `fill` //! function don't do what you want. -use crate::splitting::WordSplitter; +use crate::{Options, WordSplitter}; use unicode_width::UnicodeWidthChar; use unicode_width::UnicodeWidthStr; @@ -413,7 +413,6 @@ pub fn wrap_fragments usize>( #[cfg(test)] mod tests { use super::*; - use crate::{Options, WordSplitter}; // Like assert_eq!, but the left expression is an iterator. macro_rules! assert_iter_eq { From ad30f7069170510ab3fd5d4fa6b8bf35b5cb859d Mon Sep 17 00:00:00 2001 From: Martin Geisler Date: Sat, 14 Nov 2020 21:58:33 +0100 Subject: [PATCH 3/6] Simplify function signatures with where clauses We now have a several bounds for the generic type parameters, so a where clause can help make the signature more readable. This is reflected both in the source and on docs.rs. --- src/core.rs | 7 +++---- src/lib.rs | 15 ++++++++++----- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/core.rs b/src/core.rs index 60d0153f..344e7734 100644 --- a/src/core.rs +++ b/src/core.rs @@ -243,12 +243,11 @@ pub fn find_words(line: &str) -> impl Iterator { /// vec![Word::from("foo-bar")] /// ); /// ``` -pub fn split_words<'a, I, S: WordSplitter, T: Into>>( - words: I, - options: T, -) -> impl Iterator> +pub fn split_words<'a, I, S, Opt>(words: I, options: Opt) -> impl Iterator> where I: IntoIterator>, + S: WordSplitter, + Opt: Into>, { let options = options.into(); diff --git a/src/lib.rs b/src/lib.rs index bd691f7e..f883386c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -503,7 +503,11 @@ pub fn termwidth() -> usize { /// ``` /// /// [`wrap`]: fn.wrap.html -pub fn fill<'a, S: WordSplitter, T: Into>>(text: &str, options: T) -> String { +pub fn fill<'a, S, Opt>(text: &str, options: Opt) -> String +where + S: WordSplitter, + Opt: Into>, +{ // This will avoid reallocation in simple cases (no // indentation, no hyphenation). let mut result = String::with_capacity(text.len()); @@ -581,10 +585,11 @@ pub fn fill<'a, S: WordSplitter, T: Into>>(text: &str, options: T /// ``` /// /// [`fill`]: fn.fill.html -pub fn wrap<'a, S: WordSplitter, T: Into>>( - text: &str, - options: T, -) -> Vec> { +pub fn wrap<'a, S, Opt>(text: &str, options: Opt) -> Vec> +where + S: WordSplitter, + Opt: Into>, +{ let options = options.into(); let initial_width = options.width.saturating_sub(options.initial_indent.width()); From b948d504c2238a2c6595203fac5db062b3bc5aa1 Mon Sep 17 00:00:00 2001 From: Martin Geisler Date: Sat, 14 Nov 2020 23:09:07 +0100 Subject: [PATCH 4/6] Partially format doctests with rustfmt By adding unstable_features = true format_code_in_doc_comments = true to a .rustfmt.toml file, we can get auto-formatted doctests. However, several of our examples rely on visual alignment of lines before/after wrapping, so here I've only applied the formatting that I liked. --- src/core.rs | 56 +++++++++++++++++++++----------------- src/lib.rs | 70 ++++++++++++++++++++++++++++-------------------- src/splitting.rs | 4 +-- 3 files changed, 75 insertions(+), 55 deletions(-) diff --git a/src/core.rs b/src/core.rs index 344e7734..0b56b70a 100644 --- a/src/core.rs +++ b/src/core.rs @@ -107,8 +107,10 @@ impl<'a> Word<'a> { /// /// ``` /// use textwrap::core::Word; - /// assert_eq!(Word::from("Hello! ").break_apart(3).collect::>(), - /// vec![Word::from("Hel"), Word::from("lo! ")]); + /// assert_eq!( + /// Word::from("Hello! ").break_apart(3).collect::>(), + /// vec![Word::from("Hel"), Word::from("lo! ")] + /// ); /// ``` pub fn break_apart<'b>(&'b self, line_width: usize) -> impl Iterator> + 'b { let mut char_indices = self.word.char_indices(); @@ -176,7 +178,7 @@ impl Fragment for Word<'_> { /// # Examples /// /// ``` -/// use textwrap::core::{Fragment, Word, find_words}; +/// use textwrap::core::{find_words, Fragment, Word}; /// let words = find_words("Hello World!").collect::>(); /// assert_eq!(words, vec![Word::from("Hello "), Word::from("World!")]); /// assert_eq!(words[0].width(), 5); @@ -226,8 +228,8 @@ pub fn find_words(line: &str) -> impl Iterator { /// # Examples /// /// ``` -/// use textwrap::{Options, NoHyphenation}; -/// use textwrap::core::{Word, split_words}; +/// use textwrap::core::{split_words, Word}; +/// use textwrap::{NoHyphenation, Options}; /// /// // The default splitter is HyphenSplitter: /// let options = Options::new(80); @@ -328,14 +330,14 @@ where /// on your estimates. You can model this with a program like this: /// /// ``` -/// use textwrap::core::{Fragment, wrap_fragments}; +/// use textwrap::core::{wrap_fragments, Fragment}; /// /// #[derive(Debug)] /// struct Task<'a> { -/// name: &'a str, -/// hours: usize, // Time needed to complete task. -/// sweep: usize, // Time needed for a quick sweep after task during the day. -/// cleanup: usize, // Time needed to cleanup after task at end of day. +/// name: &'a str, +/// hours: usize, // Time needed to complete task. +/// sweep: usize, // Time needed for a quick sweep after task during the day. +/// cleanup: usize, // Time needed to cleanup after task at end of day. /// } /// /// impl Fragment for Task<'_> { @@ -359,7 +361,7 @@ where /// /// fn assign_days<'a>(tasks: &[Task<'a>], day_length: usize) -> Vec<(usize, Vec<&'a str>)> { /// let mut days = Vec::new(); -/// for day in wrap_fragments(&tasks, |i| { day_length }) { +/// for day in wrap_fragments(&tasks, |i| day_length) { /// let last = day.last().unwrap(); /// let work_hours: usize = day.iter().map(|t| t.hours + t.sweep).sum(); /// let names = day.iter().map(|t| t.name).collect::>(); @@ -369,21 +371,27 @@ where /// } /// /// // With a single crew working 8 hours a day: -/// assert_eq!(assign_days(&tasks, 8), [ -/// (7, vec!["Foundation"]), -/// (8, vec!["Framing", "Plumbing"]), -/// (7, vec!["Electrical", "Insulation"]), -/// (5, vec!["Drywall"]), -/// (7, vec!["Floors", "Countertops"]), -/// (4, vec!["Bathrooms"]), -/// ]); +/// assert_eq!( +/// assign_days(&tasks, 8), +/// [ +/// (7, vec!["Foundation"]), +/// (8, vec!["Framing", "Plumbing"]), +/// (7, vec!["Electrical", "Insulation"]), +/// (5, vec!["Drywall"]), +/// (7, vec!["Floors", "Countertops"]), +/// (4, vec!["Bathrooms"]), +/// ] +/// ); /// /// // With two crews working in shifts, 16 hours a day: -/// assert_eq!(assign_days(&tasks, 16), [ -/// (14, vec!["Foundation", "Framing", "Plumbing"]), -/// (15, vec!["Electrical", "Insulation", "Drywall", "Floors"]), -/// (6, vec!["Countertops", "Bathrooms"]), -/// ]); +/// assert_eq!( +/// assign_days(&tasks, 16), +/// [ +/// (14, vec!["Foundation", "Framing", "Plumbing"]), +/// (15, vec!["Electrical", "Insulation", "Drywall", "Floors"]), +/// (6, vec!["Countertops", "Bathrooms"]), +/// ] +/// ); /// ``` /// /// Apologies to anyone who actually knows how to build a house and diff --git a/src/lib.rs b/src/lib.rs index f883386c..f097d97f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -25,7 +25,7 @@ //! ```no_run //! # #[cfg(feature = "hyphenation")] //! use hyphenation::{Language, Load, Standard}; -//! use textwrap::{Options, fill}; +//! use textwrap::{fill, Options}; //! //! # #[cfg(feature = "hyphenation")] //! fn main() { @@ -183,7 +183,7 @@ impl<'a> Options<'a, HyphenSplitter> { /// or not. Take for example: /// /// ``` - /// use textwrap::{Options, NoHyphenation, HyphenSplitter}; + /// use textwrap::{HyphenSplitter, NoHyphenation, Options}; /// # use textwrap::{WordSplitter}; /// # let width = 80; /// @@ -211,7 +211,6 @@ impl<'a> Options<'a, HyphenSplitter> { /// Notice that the last two variables have the same type, despite the different `WordSplitter` /// in use. Thus dynamic dispatch allows to change the splitter at run-time without changing /// the variables type. - /// pub const fn new(width: usize) -> Self { Options::with_splitter(width, HyphenSplitter) } @@ -226,7 +225,7 @@ impl<'a> Options<'a, HyphenSplitter> { /// /// ```no_run /// # #![allow(unused_variables)] - /// use textwrap::{Options, termwidth}; + /// use textwrap::{termwidth, Options}; /// /// let options = Options::new(termwidth()); /// ``` @@ -269,7 +268,7 @@ impl<'a, S> Options<'a, S> { /// be in a `Box`, which then can be coerced into a trait object for dynamic dispatch: /// /// ``` - /// use textwrap::{Options, NoHyphenation, HyphenSplitter}; + /// use textwrap::{HyphenSplitter, NoHyphenation, Options}; /// # use textwrap::{WordSplitter}; /// # const width: usize = 80; /// # let expected: Options = @@ -324,7 +323,7 @@ impl<'a, S> Options<'a, S> { /// in constant and static context: /// /// ``` - /// use textwrap::{Options, HyphenSplitter}; + /// use textwrap::{HyphenSplitter, Options}; /// # use textwrap::{WordSplitter}; /// # const width: usize = 80; /// # let expected = @@ -347,7 +346,6 @@ impl<'a, S> Options<'a, S> { /// # assert_eq!(actual.break_words, expected.break_words); /// # let expected_coerced: &Options = actual; /// ``` - /// pub const fn with_splitter(width: usize, splitter: S) -> Self { Options { width, @@ -428,7 +426,7 @@ impl<'a, S: WordSplitter> Options<'a, S> { /// Take for example: /// /// ``` - /// use textwrap::{Options, HyphenSplitter, NoHyphenation}; + /// use textwrap::{HyphenSplitter, NoHyphenation, Options}; /// // The default type returned by `new` is `Options` /// let opt: Options = Options::new(80); /// // Setting a different splitter changes the type @@ -459,7 +457,7 @@ impl<'a, S: WordSplitter> Options<'a, S> { /// /// ```no_run /// # #![allow(unused_variables)] -/// use textwrap::{Options, NoHyphenation, termwidth}; +/// use textwrap::{termwidth, NoHyphenation, Options}; /// /// let width = termwidth() - 4; // Two columns on each side. /// let options = Options::new(width) @@ -487,8 +485,10 @@ pub fn termwidth() -> usize { /// ``` /// use textwrap::fill; /// -/// assert_eq!(fill("Memory safety without garbage collection.", 15), -/// "Memory safety\nwithout garbage\ncollection."); +/// 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`] @@ -497,9 +497,13 @@ pub fn termwidth() -> 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."); +/// 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." +/// ); /// ``` /// /// [`wrap`]: fn.wrap.html @@ -549,7 +553,9 @@ where /// ``` /// use textwrap::{wrap, Options}; /// -/// let options = Options::new(15).initial_indent("- ").subsequent_indent(" "); +/// let options = Options::new(15) +/// .initial_indent("- ") +/// .subsequent_indent(" "); /// let lines = wrap("Memory safety without garbage collection.", &options); /// assert_eq!(lines, &[ /// "- Memory safety", @@ -573,15 +579,21 @@ where /// /// let options = Options::new(15).subsequent_indent("...."); /// let lines = wrap("Wrapping text all day long.", &options); -/// let annotated = lines.iter().map(|line| match line { -/// Borrowed(text) => format!("[Borrowed] {}", text), -/// Owned(text) => format!("[Owned] {}", text), -/// }).collect::>(); -/// assert_eq!(annotated, &[ -/// "[Borrowed] Wrapping text", -/// "[Owned] ....all day", -/// "[Owned] ....long.", -/// ]); +/// let annotated = lines +/// .iter() +/// .map(|line| match line { +/// Borrowed(text) => format!("[Borrowed] {}", text), +/// Owned(text) => format!("[Owned] {}", text), +/// }) +/// .collect::>(); +/// assert_eq!( +/// annotated, +/// &[ +/// "[Borrowed] Wrapping text", +/// "[Owned] ....all day", +/// "[Owned] ....long.", +/// ] +/// ); /// ``` /// /// [`fill`]: fn.fill.html @@ -686,11 +698,11 @@ where /// # use textwrap::{Options, NoHyphenation}; /// # let width = 80; /// Options { -/// width: width, -/// initial_indent: "", -/// subsequent_indent: "", -/// break_words: false, -/// splitter: NoHyphenation, +/// width: width, +/// initial_indent: "", +/// subsequent_indent: "", +/// break_words: false, +/// splitter: NoHyphenation, /// }; /// ``` /// diff --git a/src/splitting.rs b/src/splitting.rs index 0d1b46f8..1afad39e 100644 --- a/src/splitting.rs +++ b/src/splitting.rs @@ -26,7 +26,7 @@ pub trait WordSplitter: std::fmt::Debug { /// # Examples /// /// ``` - /// use textwrap::{NoHyphenation, HyphenSplitter, WordSplitter}; + /// use textwrap::{HyphenSplitter, NoHyphenation, WordSplitter}; /// assert_eq!(NoHyphenation.split_points("cannot-be-split"), vec![]); /// assert_eq!(HyphenSplitter.split_points("can-be-split"), vec![4, 7]); /// ``` @@ -57,7 +57,7 @@ impl WordSplitter for &T { /// hyphenation: /// /// ``` -/// use textwrap::{wrap, Options, NoHyphenation}; +/// use textwrap::{wrap, NoHyphenation, Options}; /// /// let options = Options::new(8).splitter(NoHyphenation); /// assert_eq!(wrap("foo bar-baz", &options), From dbb1a845f9011050b27885de3de854107be2436a Mon Sep 17 00:00:00 2001 From: Martin Geisler Date: Sat, 14 Nov 2020 23:22:46 +0100 Subject: [PATCH 5/6] Simplify big doctests This removes some complicated doctests with lots of setup. I believe the coercions tested by them are already covered by other unit tests, or by the type system itself. I left the two tests which ensure that the documented output of Options::new and Options::with_splitter match reality. --- src/lib.rs | 56 ++---------------------------------------------------- 1 file changed, 2 insertions(+), 54 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index f097d97f..f8e97566 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -224,7 +224,6 @@ impl<'a> Options<'a, HyphenSplitter> { /// Equivalent to: /// /// ```no_run - /// # #![allow(unused_variables)] /// use textwrap::{termwidth, Options}; /// /// let options = Options::new(termwidth()); @@ -271,47 +270,16 @@ impl<'a, S> Options<'a, S> { /// use textwrap::{HyphenSplitter, NoHyphenation, Options}; /// # use textwrap::{WordSplitter}; /// # const width: usize = 80; - /// # let expected: Options = - /// # Options { - /// # width: width, - /// # initial_indent: "", - /// # subsequent_indent: "", - /// # break_words: true, - /// # splitter: Box::new(NoHyphenation), - /// # } - /// # ; /// /// // This opt contains a boxed trait object as splitter. - /// // Its type is actually: `Options>` /// // The type annotation is important, otherwise it will be not a trait object /// let mut opt: Options = Options::with_splitter(width, Box::new(NoHyphenation)); - /// # - /// # let actual = opt; - /// # assert_eq!(actual.width, expected.width); - /// # assert_eq!(actual.initial_indent, expected.initial_indent); - /// # assert_eq!(actual.subsequent_indent, expected.subsequent_indent); - /// # assert_eq!(actual.break_words, expected.break_words); - /// # let expected_coerced: Options> = expected; + /// // Its type is actually: `Options>`: + /// let opt_coerced: Options> = opt; /// /// // Thus, it can be overridden with a different splitter. /// opt = Options::with_splitter(width, Box::new(HyphenSplitter)); /// // Now, containing a `HyphenSplitter` instead. - /// # - /// # let expected: Options = - /// # Options { - /// # width: width, - /// # initial_indent: "", - /// # subsequent_indent: "", - /// # break_words: true, - /// # splitter: Box::new(HyphenSplitter), - /// # } - /// # ; - /// # let actual = opt; - /// # assert_eq!(actual.width, expected.width); - /// # assert_eq!(actual.initial_indent, expected.initial_indent); - /// # assert_eq!(actual.subsequent_indent, expected.subsequent_indent); - /// # assert_eq!(actual.break_words, expected.break_words); - /// # let expected_coerced: Options> = expected; /// ``` /// /// Since the splitter is given by value, which determines the generic @@ -324,27 +292,10 @@ impl<'a, S> Options<'a, S> { /// /// ``` /// use textwrap::{HyphenSplitter, Options}; - /// # use textwrap::{WordSplitter}; /// # const width: usize = 80; - /// # let expected = - /// # Options { - /// # width: width, - /// # initial_indent: "", - /// # subsequent_indent: "", - /// # break_words: true, - /// # splitter: HyphenSplitter, - /// # } - /// # ; /// /// const FOO: Options = Options::with_splitter(width, HyphenSplitter); /// static BAR: Options = FOO; - /// # - /// # let actual = &BAR; - /// # assert_eq!(actual.width, expected.width); - /// # assert_eq!(actual.initial_indent, expected.initial_indent); - /// # assert_eq!(actual.subsequent_indent, expected.subsequent_indent); - /// # assert_eq!(actual.break_words, expected.break_words); - /// # let expected_coerced: &Options = actual; /// ``` pub const fn with_splitter(width: usize, splitter: S) -> Self { Options { @@ -367,7 +318,6 @@ impl<'a, S: WordSplitter> Options<'a, S> { /// initial indentation and wrapping each paragraph by itself: /// /// ```no_run - /// # #![allow(unused_variables)] /// use textwrap::Options; /// /// let options = Options::new(15).initial_indent(" "); @@ -390,7 +340,6 @@ impl<'a, S: WordSplitter> Options<'a, S> { /// single paragraph as a bullet list: /// /// ```no_run - /// # #![allow(unused_variables)] /// use textwrap::Options; /// /// let options = Options::new(15) @@ -456,7 +405,6 @@ impl<'a, S: WordSplitter> Options<'a, S> { /// with a two column margin to the left and the right: /// /// ```no_run -/// # #![allow(unused_variables)] /// use textwrap::{termwidth, NoHyphenation, Options}; /// /// let width = termwidth() - 4; // Two columns on each side. From 351c29402cee5ea063b0b7e944b445c39f3b68df Mon Sep 17 00:00:00 2001 From: Martin Geisler Date: Sat, 14 Nov 2020 23:28:48 +0100 Subject: [PATCH 6/6] Wrap all docstrings at 70 columns for consistency This is the default fill column in Emacs and I find the short lines more readable than ~100 column wide lines. --- src/lib.rs | 70 ++++++++++++++++++++++++++++++------------------------ 1 file changed, 39 insertions(+), 31 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index f8e97566..44a96113 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -145,8 +145,8 @@ impl<'a> From for Options<'a, HyphenSplitter> { /// Constructors for boxed Options, specifically. impl<'a> Options<'a, HyphenSplitter> { - /// Creates a new `Options` with the specified width and static dispatch - /// using the `HyphenSplitter`. Equivalent to + /// Creates a new `Options` with the specified width and static + /// dispatch using the `HyphenSplitter`. Equivalent to /// /// ``` /// # use textwrap::{Options, HyphenSplitter, WordSplitter}; @@ -168,19 +168,22 @@ impl<'a> Options<'a, HyphenSplitter> { /// # let expected_coerced: Options<'static, HyphenSplitter> = expected; /// ``` /// - /// Static dispatch mean here, that the splitter is stored as-is and the - /// type is known at compile-time. Thus the returned value is actually a - /// `Options`. + /// Static dispatch mean here, that the splitter is stored as-is + /// and the type is known at compile-time. Thus the returned value + /// is actually a `Options`. /// - /// Dynamic dispatch on the other hand, mean that the splitter is stored as a trait object - /// for instance in a `Box`. This way the splitter's inner type - /// can be changed without changing the type of this struct, which then would be just - /// `Options` as a short cut for `Options>`. + /// Dynamic dispatch on the other hand, mean that the splitter is + /// stored as a trait object for instance in a `Box`. This way the splitter's inner type can be + /// changed without changing the type of this struct, which then + /// would be just `Options` as a short cut for `Options>`. /// - /// The value and type of the splitter can be choose from the start using the `with_splitter` - /// constructor or changed afterwards using the `splitter` method. Whether static or - /// dynamic dispatch is used, depends on whether these functions are given a boxed `WordSplitter` - /// or not. Take for example: + /// The value and type of the splitter can be choose from the + /// start using the `with_splitter` constructor or changed + /// afterwards using the `splitter` method. Whether static or + /// dynamic dispatch is used, depends on whether these functions + /// are given a boxed `WordSplitter` or not. Take for example: /// /// ``` /// use textwrap::{HyphenSplitter, NoHyphenation, Options}; @@ -208,9 +211,10 @@ impl<'a> Options<'a, HyphenSplitter> { /// # let opt_coerce: Options> = opt; /// ``` /// - /// Notice that the last two variables have the same type, despite the different `WordSplitter` - /// in use. Thus dynamic dispatch allows to change the splitter at run-time without changing - /// the variables type. + /// Notice that the last two variables have the same type, despite + /// the different `WordSplitter` in use. Thus dynamic dispatch + /// allows to change the splitter at run-time without changing the + /// variables type. pub const fn new(width: usize) -> Self { Options::with_splitter(width, HyphenSplitter) } @@ -238,8 +242,8 @@ impl<'a> Options<'a, HyphenSplitter> { } impl<'a, S> Options<'a, S> { - /// Creates a new `Options` with the specified width and splitter. Equivalent - /// to + /// Creates a new `Options` with the specified width and splitter. + /// Equivalent to /// /// ``` /// # use textwrap::{Options, NoHyphenation, HyphenSplitter}; @@ -262,9 +266,11 @@ impl<'a, S> Options<'a, S> { /// # let expected_coerced: Options<'static, NoHyphenation> = expected; /// ``` /// - /// This constructor allows to specify the splitter to be used. It is like a short-cut for - /// `Options::new(w).splitter(s)`, but this function is a `const fn`. The given splitter may - /// be in a `Box`, which then can be coerced into a trait object for dynamic dispatch: + /// This constructor allows to specify the splitter to be used. It + /// is like a short-cut for `Options::new(w).splitter(s)`, but + /// this function is a `const fn`. The given splitter may be in a + /// `Box`, which then can be coerced into a trait object for + /// dynamic dispatch: /// /// ``` /// use textwrap::{HyphenSplitter, NoHyphenation, Options}; @@ -282,13 +288,14 @@ impl<'a, S> Options<'a, S> { /// // Now, containing a `HyphenSplitter` instead. /// ``` /// - /// Since the splitter is given by value, which determines the generic - /// type parameter, it can be used to produce both an `Options` with static - /// and dynamic dispatch, respectively. - /// While dynamic dispatch allows to change the type of the inner splitter - /// at run time as seen above, static dispatch especially can store the splitter - /// directly, without the need for a box. This in turn allows it to be used - /// in constant and static context: + /// Since the splitter is given by value, which determines the + /// generic type parameter, it can be used to produce both an + /// `Options` with static and dynamic dispatch, respectively. + /// While dynamic dispatch allows to change the type of the inner + /// splitter at run time as seen above, static dispatch especially + /// can store the splitter directly, without the need for a box. + /// This in turn allows it to be used in constant and static + /// context: /// /// ``` /// use textwrap::{HyphenSplitter, Options}; @@ -370,9 +377,10 @@ impl<'a, S: WordSplitter> Options<'a, S> { /// Change [`self.splitter`]. The [`WordSplitter`] is used to fit /// part of a word into the current line when wrapping text. /// - /// This function may return a different type than `Self`. That is the case when the given - /// `splitter` is of a different type the the currently stored one in the `splitter` field. - /// Take for example: + /// This function may return a different type than `Self`. That is + /// the case when the given `splitter` is of a different type the + /// the currently stored one in the `splitter` field. Take for + /// example: /// /// ``` /// use textwrap::{HyphenSplitter, NoHyphenation, Options};