Trait split_paragraphs::ParagraphsExt
source · pub trait ParagraphsExt {
// Required method
fn paragraphs(&self) -> Paragraphs<'_> ⓘ;
}Expand description
Trait extending str with the paragraphs method.
See its documentation for more.
Required Methods§
sourcefn paragraphs(&self) -> Paragraphs<'_> ⓘ
fn paragraphs(&self) -> Paragraphs<'_> ⓘ
An iterator over the paragraphs of a string, as string slices.
Paragraphs consist of one or more lines of text containing non-whitespace characters surrounded by lines that only contain whitespace characters.
[paragraphs] mirrors the behavior of the standard library’s [lines].
See its documentation for more details.
§Examples
Basic usage:
let text = "foo\r\nbar\n\nbaz\r";
let mut paragraphs = text.paragraphs();
assert_eq!(Some("foo\r\nbar"), paragraphs.next());
// Trailing carriage return is included in the last paragraph
assert_eq!(Some("baz\r"), paragraphs.next());
assert_eq!(None, paragraphs.next());The final paragraph does not require any ending:
let text = "\n\n\nfoo\nbar\n\r\nbaz";
let mut paragraphs = text.paragraphs();
assert_eq!(Some("foo\nbar"), paragraphs.next());
assert_eq!(Some("baz"), paragraphs.next());
assert_eq!(None, paragraphs.next());