pub struct Parser<'input, F = DefaultBrokenLinkCallback> { /* private fields */ }
Expand description
Markdown event iterator.
Implementations§
source§impl<'input> Parser<'input, DefaultBrokenLinkCallback>
impl<'input> Parser<'input, DefaultBrokenLinkCallback>
sourcepub fn new(text: &'input str) -> Self
pub fn new(text: &'input str) -> Self
Creates a new event iterator for a markdown string without any options enabled.
Examples found in repository?
examples/events.rs (line 12)
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
fn main() {
let mut text = String::new();
std::io::stdin().read_to_string(&mut text).unwrap();
eprintln!("{text:?} -> [");
let mut width = 0;
for event in Parser::new(&text) {
if let Event::End(_) = event {
width -= 2;
}
eprintln!(" {:width$}{event:?}", "");
if let Event::Start(_) = event {
width += 2;
}
}
eprintln!("]");
}
More examples
examples/parser-map-event-print.rs (line 14)
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
fn main() {
let markdown_input = "# Example Heading\nExample paragraph with **lorem** _ipsum_ text.";
println!(
"\nParsing the following markdown string:\n{}\n",
markdown_input
);
// Set up the parser. We can treat is as any other iterator.
// For each event, we print its details, such as the tag or string.
// This filter simply returns the same event without any changes;
// you can compare the `event-filter` example which alters the output.
let parser = Parser::new(markdown_input).map(|event| {
match &event {
Event::Start(tag) => println!("Start: {:?}", tag),
Event::End(tag) => println!("End: {:?}", tag),
Event::Html(s) => println!("Html: {:?}", s),
Event::InlineHtml(s) => println!("InlineHtml: {:?}", s),
Event::Text(s) => println!("Text: {:?}", s),
Event::Code(s) => println!("Code: {:?}", s),
Event::DisplayMath(s) => println!("DisplayMath: {:?}", s),
Event::InlineMath(s) => println!("Math: {:?}", s),
Event::FootnoteReference(s) => println!("FootnoteReference: {:?}", s),
Event::TaskListMarker(b) => println!("TaskListMarker: {:?}", b),
Event::SoftBreak => println!("SoftBreak"),
Event::HardBreak => println!("HardBreak"),
Event::Rule => println!("Rule"),
};
event
});
let mut html_output = String::new();
html::push_html(&mut html_output, parser);
println!("\nHTML output:\n{}\n", &html_output);
}
sourcepub fn new_ext(text: &'input str, options: Options) -> Self
pub fn new_ext(text: &'input str, options: Options) -> Self
Creates a new event iterator for a markdown string with given options.
Examples found in repository?
examples/string-to-string.rs (line 11)
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
fn main() {
let markdown_input: &str = "Hello world, this is a ~~complicated~~ *very simple* example.";
println!("Parsing the following markdown string:\n{}", markdown_input);
// Set up options and parser. Strikethroughs are not part of the CommonMark standard
// and we therefore must enable it explicitly.
let mut options = Options::empty();
options.insert(Options::ENABLE_STRIKETHROUGH);
let parser = Parser::new_ext(markdown_input, options);
// Write to String buffer.
let mut html_output: String = String::with_capacity(markdown_input.len() * 3 / 2);
html::push_html(&mut html_output, parser);
// Check that the output is what we expected.
let expected_html: &str =
"<p>Hello world, this is a <del>complicated</del> <em>very simple</em> example.</p>\n";
assert_eq!(expected_html, &html_output);
// Write result to stdout.
println!("\nHTML output:\n{}", &html_output);
}
More examples
examples/event-filter.rs (line 11)
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
fn main() {
let markdown_input: &str = "This is Peter on ![holiday in Greece](pearl_beach.jpg).";
println!("Parsing the following markdown string:\n{}", markdown_input);
// Set up parser. We can treat is as any other iterator. We replace Peter by John
// and image by its alt text.
let parser = Parser::new_ext(markdown_input, Options::empty())
.map(|event| match event {
Event::Text(text) => Event::Text(text.replace("Peter", "John").into()),
_ => event,
})
.filter(|event| match event {
Event::Start(Tag::Image { .. }) | Event::End(TagEnd::Image) => false,
_ => true,
});
// Write to anything implementing the `Write` trait. This could also be a file
// or network socket.
let stdout = std::io::stdout();
let mut handle = stdout.lock();
handle.write_all(b"\nHTML output:\n").unwrap();
html::write_html_io(&mut handle, parser).unwrap();
}
examples/parser-map-tag-print.rs (line 45)
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
fn main() {
let markdown_input = concat!(
"# My Heading\n",
"\n",
"My paragraph.\n",
"\n",
"* a\n",
"* b\n",
"* c\n",
"\n",
"1. d\n",
"2. e\n",
"3. f\n",
"\n",
"> my block quote\n",
"\n",
"```\n",
"my code block\n",
"```\n",
"\n",
"*emphasis*\n",
"**strong**\n",
"~~strikethrough~~\n",
"[My Link](http://example.com)\n",
"![My Image](http://example.com/image.jpg)\n",
"\n",
"| a | b |\n",
"| - | - |\n",
"| c | d |\n",
"\n",
"hello[^1]\n",
"[^1]: my footnote\n",
);
println!(
"\nParsing the following markdown string:\n{}\n",
markdown_input
);
// Set up the parser. We can treat is as any other iterator.
// For each event, we print its details, such as the tag or string.
// This filter simply returns the same event without any changes;
// you can compare the `event-filter` example which alters the output.
let parser = Parser::new_ext(markdown_input, Options::all()).map(|event| {
match &event {
Event::Start(tag) => match tag {
Tag::HtmlBlock => println!("HtmlBlock"),
Tag::Heading {
level,
id,
classes,
attrs,
} => println!(
"Heading heading_level: {} fragment identifier: {:?} classes: {:?} attrs: {:?}",
level, id, classes, attrs
),
Tag::Paragraph => println!("Paragraph"),
Tag::List(ordered_list_first_item_number) => println!(
"List ordered_list_first_item_number: {:?}",
ordered_list_first_item_number
),
Tag::DefinitionList => println!("Definition list"),
Tag::DefinitionListTitle => println!("Definition title (definition list item)"),
Tag::DefinitionListDefinition => println!("Definition (definition list item)"),
Tag::Item => println!("Item (this is a list item)"),
Tag::Emphasis => println!("Emphasis (this is a span tag)"),
Tag::Strong => println!("Strong (this is a span tag)"),
Tag::Strikethrough => println!("Strikethrough (this is a span tag)"),
Tag::BlockQuote(kind) => println!("BlockQuote ({:?})", kind),
Tag::CodeBlock(code_block_kind) => {
println!("CodeBlock code_block_kind: {:?}", code_block_kind)
}
Tag::Link {
link_type,
dest_url,
title,
id,
} => println!(
"Link link_type: {:?} url: {} title: {} id: {}",
link_type, dest_url, title, id
),
Tag::Image {
link_type,
dest_url,
title,
id,
} => println!(
"Image link_type: {:?} url: {} title: {} id: {}",
link_type, dest_url, title, id
),
Tag::Table(column_text_alignment_list) => println!(
"Table column_text_alignment_list: {:?}",
column_text_alignment_list
),
Tag::TableHead => println!("TableHead (contains TableRow tags"),
Tag::TableRow => println!("TableRow (contains TableCell tags)"),
Tag::TableCell => println!("TableCell (contains inline tags)"),
Tag::FootnoteDefinition(label) => println!("FootnoteDefinition label: {}", label),
Tag::MetadataBlock(kind) => println!("MetadataBlock: {:?}", kind),
},
_ => (),
};
event
});
let mut html_output = String::new();
pulldown_cmark::html::push_html(&mut html_output, parser);
println!("\nHTML output:\n{}\n", &html_output);
}
examples/footnote-rewrite.rs (line 18)
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
fn main() {
let markdown_input: &str = "This is an [^a] footnote [^a].\n\n[^a]: footnote contents";
println!("Parsing the following markdown string:\n{}", markdown_input);
// To generate this style, you have to collect the footnotes at the end, while parsing.
// You also need to count usages.
let mut footnotes = Vec::new();
let mut in_footnote = Vec::new();
let mut footnote_numbers = HashMap::new();
// ENABLE_FOOTNOTES is used in this example, but ENABLE_OLD_FOOTNOTES would work, too.
let parser = Parser::new_ext(markdown_input, Options::ENABLE_FOOTNOTES)
.filter_map(|event| {
match event {
Event::Start(Tag::FootnoteDefinition(_)) => {
in_footnote.push(vec![event]);
None
}
Event::End(TagEnd::FootnoteDefinition) => {
let mut f = in_footnote.pop().unwrap();
f.push(event);
footnotes.push(f);
None
}
Event::FootnoteReference(name) => {
let n = footnote_numbers.len() + 1;
let (n, nr) = footnote_numbers.entry(name.clone()).or_insert((n, 0usize));
*nr += 1;
let html = Event::Html(format!(r##"<sup class="footnote-reference" id="fr-{name}-{nr}"><a href="#fn-{name}">[{n}]</a></sup>"##).into());
if in_footnote.is_empty() {
Some(html)
} else {
in_footnote.last_mut().unwrap().push(html);
None
}
}
_ if !in_footnote.is_empty() => {
in_footnote.last_mut().unwrap().push(event);
None
}
_ => Some(event),
}
});
// Write to anything implementing the `Write` trait. This could also be a file
// or network socket.
let stdout = std::io::stdout();
let mut handle = stdout.lock();
handle.write_all(b"\nHTML output:\n").unwrap();
html::write_html_io(&mut handle, parser).unwrap();
// To make the footnotes look right, we need to sort them by their appearance order, not by
// the in-tree order of their actual definitions. Unused items are omitted entirely.
//
// For example, this code:
//
// test [^1] [^2]
// [^2]: second used, first defined
// [^1]: test
//
// Gets rendered like *this* if you copy it into a GitHub comment box:
//
// <p>test <sup>[1]</sup> <sup>[2]</sup></p>
// <hr>
// <ol>
// <li>test ↩</li>
// <li>second used, first defined ↩</li>
// </ol>
if !footnotes.is_empty() {
footnotes.retain(|f| match f.first() {
Some(Event::Start(Tag::FootnoteDefinition(name))) => {
footnote_numbers.get(name).unwrap_or(&(0, 0)).1 != 0
}
_ => false,
});
footnotes.sort_by_cached_key(|f| match f.first() {
Some(Event::Start(Tag::FootnoteDefinition(name))) => {
footnote_numbers.get(name).unwrap_or(&(0, 0)).0
}
_ => unreachable!(),
});
handle
.write_all(b"<hr><ol class=\"footnotes-list\">\n")
.unwrap();
html::write_html_io(
&mut handle,
footnotes.into_iter().flat_map(|fl| {
// To write backrefs, the name needs kept until the end of the footnote definition.
let mut name = CowStr::from("");
// Backrefs are included in the final paragraph of the footnote, if it's normal text.
// For example, this DOM can be produced:
//
// Markdown:
//
// five [^feet].
//
// [^feet]:
// A foot is defined, in this case, as 0.3048 m.
//
// Historically, the foot has not been defined this way, corresponding to many
// subtly different units depending on the location.
//
// HTML:
//
// <p>five <sup class="footnote-reference" id="fr-feet-1"><a href="#fn-feet">[1]</a></sup>.</p>
//
// <ol class="footnotes-list">
// <li id="fn-feet">
// <p>A foot is defined, in this case, as 0.3048 m.</p>
// <p>Historically, the foot has not been defined this way, corresponding to many
// subtly different units depending on the location. <a href="#fr-feet-1">↩</a></p>
// </li>
// </ol>
//
// This is mostly a visual hack, so that footnotes use less vertical space.
//
// If there is no final paragraph, such as a tabular, list, or image footnote, it gets
// pushed after the last tag instead.
let mut has_written_backrefs = false;
let fl_len = fl.len();
let footnote_numbers = &footnote_numbers;
fl.into_iter().enumerate().map(move |(i, f)| match f {
Event::Start(Tag::FootnoteDefinition(current_name)) => {
name = current_name;
has_written_backrefs = false;
Event::Html(format!(r##"<li id="fn-{name}">"##).into())
}
Event::End(TagEnd::FootnoteDefinition) | Event::End(TagEnd::Paragraph)
if !has_written_backrefs && i >= fl_len - 2 =>
{
let usage_count = footnote_numbers.get(&name).unwrap().1;
let mut end = String::with_capacity(
name.len() + (r##" <a href="#fr--1">↩</a></li>"##.len() * usage_count),
);
for usage in 1..=usage_count {
if usage == 1 {
write!(&mut end, r##" <a href="#fr-{name}-{usage}">↩</a>"##)
.unwrap();
} else {
write!(&mut end, r##" <a href="#fr-{name}-{usage}">↩{usage}</a>"##)
.unwrap();
}
}
has_written_backrefs = true;
if f == Event::End(TagEnd::FootnoteDefinition) {
end.push_str("</li>\n");
} else {
end.push_str("</p>\n");
}
Event::Html(end.into())
}
Event::End(TagEnd::FootnoteDefinition) => Event::Html("</li>\n".into()),
Event::FootnoteReference(_) => unreachable!("converted to HTML earlier"),
f => f,
})
}),
)
.unwrap();
handle.write_all(b"</ol>\n").unwrap();
}
}
source§impl<'input, F: BrokenLinkCallback<'input>> Parser<'input, F>
impl<'input, F: BrokenLinkCallback<'input>> Parser<'input, F>
sourcepub fn new_with_broken_link_callback(
text: &'input str,
options: Options,
broken_link_callback: Option<F>,
) -> Self
pub fn new_with_broken_link_callback( text: &'input str, options: Options, broken_link_callback: Option<F>, ) -> Self
In case the parser encounters any potential links that have a broken
reference (e.g [foo]
when there is no [foo]:
entry at the bottom)
the provided callback will be called with the reference name,
and the returned pair will be used as the link URL and title if it is not
None
.
Examples found in repository?
examples/broken-link-callbacks.rs (line 22)
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
fn main() {
let input: &str = "Hello world, check out [my website][].";
println!("Parsing the following markdown string:\n{}", input);
// Setup callback that sets the URL and title when it encounters
// a reference to our home page.
let callback = |broken_link: BrokenLink| {
if broken_link.reference.as_ref() == "my website" {
println!(
"Replacing the markdown `{}` of type {:?} with a working link",
&input[broken_link.span], broken_link.link_type,
);
Some(("http://example.com".into(), "my example website".into()))
} else {
None
}
};
// Create a parser with our callback function for broken links.
let parser = Parser::new_with_broken_link_callback(input, Options::empty(), Some(callback));
// Write to String buffer.
let mut html_output: String = String::with_capacity(input.len() * 3 / 2);
html::push_html(&mut html_output, parser);
// Check that the output is what we expected.
let expected_html: &str =
"<p>Hello world, check out <a href=\"http://example.com\" title=\"my example website\">my website</a>.</p>\n";
assert_eq!(expected_html, &html_output);
// Write result to stdout.
println!("\nHTML output:\n{}", &html_output);
}
sourcepub fn reference_definitions(&self) -> &RefDefs<'_>
pub fn reference_definitions(&self) -> &RefDefs<'_>
Returns a reference to the internal RefDefs
object, which provides access
to the internal map of reference definitions.
sourcepub fn into_offset_iter(self) -> OffsetIter<'input, F> ⓘ
pub fn into_offset_iter(self) -> OffsetIter<'input, F> ⓘ
Consumes the event iterator and produces an iterator that produces
(Event, Range)
pairs, where the Range
value maps to the corresponding
range in the markdown source.
Trait Implementations§
source§impl<'a, F: BrokenLinkCallback<'a>> Iterator for Parser<'a, F>
impl<'a, F: BrokenLinkCallback<'a>> Iterator for Parser<'a, F>
source§fn next(&mut self) -> Option<Event<'a>>
fn next(&mut self) -> Option<Event<'a>>
Advances the iterator and returns the next value. Read more
source§fn next_chunk<const N: usize>(
&mut self,
) -> Result<[Self::Item; N], IntoIter<Self::Item, N>>where
Self: Sized,
fn next_chunk<const N: usize>(
&mut self,
) -> Result<[Self::Item; N], IntoIter<Self::Item, N>>where
Self: Sized,
🔬This is a nightly-only experimental API. (
iter_next_chunk
)Advances the iterator and returns an array containing the next
N
values. Read more1.0.0 · source§fn size_hint(&self) -> (usize, Option<usize>)
fn size_hint(&self) -> (usize, Option<usize>)
Returns the bounds on the remaining length of the iterator. Read more
1.0.0 · source§fn count(self) -> usizewhere
Self: Sized,
fn count(self) -> usizewhere
Self: Sized,
Consumes the iterator, counting the number of iterations and returning it. Read more
1.0.0 · source§fn last(self) -> Option<Self::Item>where
Self: Sized,
fn last(self) -> Option<Self::Item>where
Self: Sized,
Consumes the iterator, returning the last element. Read more
source§fn advance_by(&mut self, n: usize) -> Result<(), NonZero<usize>>
fn advance_by(&mut self, n: usize) -> Result<(), NonZero<usize>>
🔬This is a nightly-only experimental API. (
iter_advance_by
)Advances the iterator by
n
elements. Read more1.0.0 · source§fn nth(&mut self, n: usize) -> Option<Self::Item>
fn nth(&mut self, n: usize) -> Option<Self::Item>
Returns the
n
th element of the iterator. Read more1.28.0 · source§fn step_by(self, step: usize) -> StepBy<Self>where
Self: Sized,
fn step_by(self, step: usize) -> StepBy<Self>where
Self: Sized,
Creates an iterator starting at the same point, but stepping by
the given amount at each iteration. Read more
1.0.0 · source§fn chain<U>(self, other: U) -> Chain<Self, <U as IntoIterator>::IntoIter>
fn chain<U>(self, other: U) -> Chain<Self, <U as IntoIterator>::IntoIter>
Takes two iterators and creates a new iterator over both in sequence. Read more
1.0.0 · source§fn zip<U>(self, other: U) -> Zip<Self, <U as IntoIterator>::IntoIter>where
Self: Sized,
U: IntoIterator,
fn zip<U>(self, other: U) -> Zip<Self, <U as IntoIterator>::IntoIter>where
Self: Sized,
U: IntoIterator,
‘Zips up’ two iterators into a single iterator of pairs. Read more
source§fn intersperse_with<G>(self, separator: G) -> IntersperseWith<Self, G>
fn intersperse_with<G>(self, separator: G) -> IntersperseWith<Self, G>
🔬This is a nightly-only experimental API. (
iter_intersperse
)Creates a new iterator which places an item generated by
separator
between adjacent items of the original iterator. Read more1.0.0 · source§fn map<B, F>(self, f: F) -> Map<Self, F>
fn map<B, F>(self, f: F) -> Map<Self, F>
Takes a closure and creates an iterator which calls that closure on each
element. Read more
1.0.0 · source§fn filter<P>(self, predicate: P) -> Filter<Self, P>
fn filter<P>(self, predicate: P) -> Filter<Self, P>
Creates an iterator which uses a closure to determine if an element
should be yielded. Read more
1.0.0 · source§fn filter_map<B, F>(self, f: F) -> FilterMap<Self, F>
fn filter_map<B, F>(self, f: F) -> FilterMap<Self, F>
Creates an iterator that both filters and maps. Read more
1.0.0 · source§fn enumerate(self) -> Enumerate<Self>where
Self: Sized,
fn enumerate(self) -> Enumerate<Self>where
Self: Sized,
Creates an iterator which gives the current iteration count as well as
the next value. Read more
1.0.0 · source§fn skip_while<P>(self, predicate: P) -> SkipWhile<Self, P>
fn skip_while<P>(self, predicate: P) -> SkipWhile<Self, P>
1.0.0 · source§fn take_while<P>(self, predicate: P) -> TakeWhile<Self, P>
fn take_while<P>(self, predicate: P) -> TakeWhile<Self, P>
Creates an iterator that yields elements based on a predicate. Read more
1.57.0 · source§fn map_while<B, P>(self, predicate: P) -> MapWhile<Self, P>
fn map_while<B, P>(self, predicate: P) -> MapWhile<Self, P>
Creates an iterator that both yields elements based on a predicate and maps. Read more
1.0.0 · source§fn skip(self, n: usize) -> Skip<Self>where
Self: Sized,
fn skip(self, n: usize) -> Skip<Self>where
Self: Sized,
Creates an iterator that skips the first
n
elements. Read more1.0.0 · source§fn take(self, n: usize) -> Take<Self>where
Self: Sized,
fn take(self, n: usize) -> Take<Self>where
Self: Sized,
Creates an iterator that yields the first
n
elements, or fewer
if the underlying iterator ends sooner. Read more1.0.0 · source§fn flat_map<U, F>(self, f: F) -> FlatMap<Self, U, F>
fn flat_map<U, F>(self, f: F) -> FlatMap<Self, U, F>
Creates an iterator that works like map, but flattens nested structure. Read more
source§fn map_windows<F, R, const N: usize>(self, f: F) -> MapWindows<Self, F, N>
fn map_windows<F, R, const N: usize>(self, f: F) -> MapWindows<Self, F, N>
🔬This is a nightly-only experimental API. (
iter_map_windows
)Calls the given function
f
for each contiguous window of size N
over
self
and returns an iterator over the outputs of f
. Like slice::windows()
,
the windows during mapping overlap as well. Read more1.0.0 · source§fn inspect<F>(self, f: F) -> Inspect<Self, F>
fn inspect<F>(self, f: F) -> Inspect<Self, F>
Does something with each element of an iterator, passing the value on. Read more
1.0.0 · source§fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
Borrows an iterator, rather than consuming it. Read more
source§fn collect_into<E>(self, collection: &mut E) -> &mut E
fn collect_into<E>(self, collection: &mut E) -> &mut E
🔬This is a nightly-only experimental API. (
iter_collect_into
)Collects all the items from an iterator into a collection. Read more
1.0.0 · source§fn partition<B, F>(self, f: F) -> (B, B)
fn partition<B, F>(self, f: F) -> (B, B)
Consumes an iterator, creating two collections from it. Read more
source§fn is_partitioned<P>(self, predicate: P) -> bool
fn is_partitioned<P>(self, predicate: P) -> bool
🔬This is a nightly-only experimental API. (
iter_is_partitioned
)Checks if the elements of this iterator are partitioned according to the given predicate,
such that all those that return
true
precede all those that return false
. Read more1.27.0 · source§fn try_fold<B, F, R>(&mut self, init: B, f: F) -> R
fn try_fold<B, F, R>(&mut self, init: B, f: F) -> R
An iterator method that applies a function as long as it returns
successfully, producing a single, final value. Read more
1.27.0 · source§fn try_for_each<F, R>(&mut self, f: F) -> R
fn try_for_each<F, R>(&mut self, f: F) -> R
An iterator method that applies a fallible function to each item in the
iterator, stopping at the first error and returning that error. Read more
1.0.0 · source§fn fold<B, F>(self, init: B, f: F) -> B
fn fold<B, F>(self, init: B, f: F) -> B
Folds every element into an accumulator by applying an operation,
returning the final result. Read more
1.51.0 · source§fn reduce<F>(self, f: F) -> Option<Self::Item>
fn reduce<F>(self, f: F) -> Option<Self::Item>
Reduces the elements to a single one, by repeatedly applying a reducing
operation. Read more
source§fn try_reduce<R>(
&mut self,
f: impl FnMut(Self::Item, Self::Item) -> R,
) -> <<R as Try>::Residual as Residual<Option<<R as Try>::Output>>>::TryType
fn try_reduce<R>( &mut self, f: impl FnMut(Self::Item, Self::Item) -> R, ) -> <<R as Try>::Residual as Residual<Option<<R as Try>::Output>>>::TryType
🔬This is a nightly-only experimental API. (
iterator_try_reduce
)Reduces the elements to a single one by repeatedly applying a reducing operation. If the
closure returns a failure, the failure is propagated back to the caller immediately. Read more
1.0.0 · source§fn all<F>(&mut self, f: F) -> bool
fn all<F>(&mut self, f: F) -> bool
Tests if every element of the iterator matches a predicate. Read more
1.0.0 · source§fn any<F>(&mut self, f: F) -> bool
fn any<F>(&mut self, f: F) -> bool
Tests if any element of the iterator matches a predicate. Read more
1.0.0 · source§fn find<P>(&mut self, predicate: P) -> Option<Self::Item>
fn find<P>(&mut self, predicate: P) -> Option<Self::Item>
Searches for an element of an iterator that satisfies a predicate. Read more
1.30.0 · source§fn find_map<B, F>(&mut self, f: F) -> Option<B>
fn find_map<B, F>(&mut self, f: F) -> Option<B>
Applies function to the elements of iterator and returns
the first non-none result. Read more
source§fn try_find<R>(
&mut self,
f: impl FnMut(&Self::Item) -> R,
) -> <<R as Try>::Residual as Residual<Option<Self::Item>>>::TryType
fn try_find<R>( &mut self, f: impl FnMut(&Self::Item) -> R, ) -> <<R as Try>::Residual as Residual<Option<Self::Item>>>::TryType
🔬This is a nightly-only experimental API. (
try_find
)Applies function to the elements of iterator and returns
the first true result or the first error. Read more
1.0.0 · source§fn position<P>(&mut self, predicate: P) -> Option<usize>
fn position<P>(&mut self, predicate: P) -> Option<usize>
Searches for an element in an iterator, returning its index. Read more
1.6.0 · source§fn max_by_key<B, F>(self, f: F) -> Option<Self::Item>
fn max_by_key<B, F>(self, f: F) -> Option<Self::Item>
Returns the element that gives the maximum value from the
specified function. Read more
1.15.0 · source§fn max_by<F>(self, compare: F) -> Option<Self::Item>
fn max_by<F>(self, compare: F) -> Option<Self::Item>
Returns the element that gives the maximum value with respect to the
specified comparison function. Read more
1.6.0 · source§fn min_by_key<B, F>(self, f: F) -> Option<Self::Item>
fn min_by_key<B, F>(self, f: F) -> Option<Self::Item>
Returns the element that gives the minimum value from the
specified function. Read more
1.15.0 · source§fn min_by<F>(self, compare: F) -> Option<Self::Item>
fn min_by<F>(self, compare: F) -> Option<Self::Item>
Returns the element that gives the minimum value with respect to the
specified comparison function. Read more
1.0.0 · source§fn unzip<A, B, FromA, FromB>(self) -> (FromA, FromB)
fn unzip<A, B, FromA, FromB>(self) -> (FromA, FromB)
Converts an iterator of pairs into a pair of containers. Read more
1.36.0 · source§fn copied<'a, T>(self) -> Copied<Self>
fn copied<'a, T>(self) -> Copied<Self>
Creates an iterator which copies all of its elements. Read more
source§fn array_chunks<const N: usize>(self) -> ArrayChunks<Self, N>where
Self: Sized,
fn array_chunks<const N: usize>(self) -> ArrayChunks<Self, N>where
Self: Sized,
🔬This is a nightly-only experimental API. (
iter_array_chunks
)Returns an iterator over
N
elements of the iterator at a time. Read more1.11.0 · source§fn product<P>(self) -> P
fn product<P>(self) -> P
Iterates over the entire iterator, multiplying all the elements Read more
source§fn cmp_by<I, F>(self, other: I, cmp: F) -> Ordering
fn cmp_by<I, F>(self, other: I, cmp: F) -> Ordering
🔬This is a nightly-only experimental API. (
iter_order_by
)Lexicographically compares the elements of this
Iterator
with those
of another with respect to the specified comparison function. Read more1.5.0 · source§fn partial_cmp<I>(self, other: I) -> Option<Ordering>
fn partial_cmp<I>(self, other: I) -> Option<Ordering>
Lexicographically compares the
PartialOrd
elements of
this Iterator
with those of another. The comparison works like short-circuit
evaluation, returning a result without comparing the remaining elements.
As soon as an order can be determined, the evaluation stops and a result is returned. Read moresource§fn partial_cmp_by<I, F>(self, other: I, partial_cmp: F) -> Option<Ordering>where
Self: Sized,
I: IntoIterator,
F: FnMut(Self::Item, <I as IntoIterator>::Item) -> Option<Ordering>,
fn partial_cmp_by<I, F>(self, other: I, partial_cmp: F) -> Option<Ordering>where
Self: Sized,
I: IntoIterator,
F: FnMut(Self::Item, <I as IntoIterator>::Item) -> Option<Ordering>,
🔬This is a nightly-only experimental API. (
iter_order_by
)Lexicographically compares the elements of this
Iterator
with those
of another with respect to the specified comparison function. Read moresource§fn eq_by<I, F>(self, other: I, eq: F) -> bool
fn eq_by<I, F>(self, other: I, eq: F) -> bool
🔬This is a nightly-only experimental API. (
iter_order_by
)1.5.0 · source§fn lt<I>(self, other: I) -> bool
fn lt<I>(self, other: I) -> bool
Determines if the elements of this
Iterator
are lexicographically
less than those of another. Read more1.5.0 · source§fn le<I>(self, other: I) -> bool
fn le<I>(self, other: I) -> bool
Determines if the elements of this
Iterator
are lexicographically
less or equal to those of another. Read more1.5.0 · source§fn gt<I>(self, other: I) -> bool
fn gt<I>(self, other: I) -> bool
Determines if the elements of this
Iterator
are lexicographically
greater than those of another. Read more1.5.0 · source§fn ge<I>(self, other: I) -> bool
fn ge<I>(self, other: I) -> bool
Determines if the elements of this
Iterator
are lexicographically
greater than or equal to those of another. Read more1.82.0 · source§fn is_sorted_by<F>(self, compare: F) -> bool
fn is_sorted_by<F>(self, compare: F) -> bool
Checks if the elements of this iterator are sorted using the given comparator function. Read more
1.82.0 · source§fn is_sorted_by_key<F, K>(self, f: F) -> bool
fn is_sorted_by_key<F, K>(self, f: F) -> bool
Checks if the elements of this iterator are sorted using the given key extraction
function. Read more
impl<'a, F: BrokenLinkCallback<'a>> FusedIterator for Parser<'a, F>
Auto Trait Implementations§
impl<'input, F> Freeze for Parser<'input, F>where
F: Freeze,
impl<'input, F> RefUnwindSafe for Parser<'input, F>where
F: RefUnwindSafe,
impl<'input, F> Send for Parser<'input, F>where
F: Send,
impl<'input, F> Sync for Parser<'input, F>where
F: Sync,
impl<'input, F> Unpin for Parser<'input, F>where
F: Unpin,
impl<'input, F> UnwindSafe for Parser<'input, F>where
F: UnwindSafe,
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more