Struct Parser

Source
pub struct Parser<'input, F = DefaultBrokenLinkCallback> { /* private fields */ }
Expand description

Markdown event iterator.

Implementations§

Source§

impl<'input> Parser<'input, DefaultBrokenLinkCallback>

Source

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)
6fn main() {
7    let mut text = String::new();
8    std::io::stdin().read_to_string(&mut text).unwrap();
9
10    eprintln!("{text:?} -> [");
11    let mut width = 0;
12    for event in Parser::new(&text) {
13        if let Event::End(_) = event {
14            width -= 2;
15        }
16        eprintln!("  {:width$}{event:?}", "");
17        if let Event::Start(_) = event {
18            width += 2;
19        }
20    }
21    eprintln!("]");
22}
More examples
Hide additional examples
examples/parser-map-event-print.rs (line 14)
3fn main() {
4    let markdown_input = "# Example Heading\nExample paragraph with **lorem** _ipsum_ text.";
5    println!(
6        "\nParsing the following markdown string:\n{}\n",
7        markdown_input
8    );
9
10    // Set up the parser. We can treat is as any other iterator.
11    // For each event, we print its details, such as the tag or string.
12    // This filter simply returns the same event without any changes;
13    // you can compare the `event-filter` example which alters the output.
14    let parser = Parser::new(markdown_input).map(|event| {
15        match &event {
16            Event::Start(tag) => println!("Start: {:?}", tag),
17            Event::End(tag) => println!("End: {:?}", tag),
18            Event::Html(s) => println!("Html: {:?}", s),
19            Event::InlineHtml(s) => println!("InlineHtml: {:?}", s),
20            Event::Text(s) => println!("Text: {:?}", s),
21            Event::Code(s) => println!("Code: {:?}", s),
22            Event::DisplayMath(s) => println!("DisplayMath: {:?}", s),
23            Event::InlineMath(s) => println!("Math: {:?}", s),
24            Event::FootnoteReference(s) => println!("FootnoteReference: {:?}", s),
25            Event::TaskListMarker(b) => println!("TaskListMarker: {:?}", b),
26            Event::SoftBreak => println!("SoftBreak"),
27            Event::HardBreak => println!("HardBreak"),
28            Event::Rule => println!("Rule"),
29        };
30        event
31    });
32
33    let mut html_output = String::new();
34    html::push_html(&mut html_output, parser);
35    println!("\nHTML output:\n{}\n", &html_output);
36}
Source

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)
3fn main() {
4    let markdown_input: &str = "Hello world, this is a ~~complicated~~ *very simple* example.";
5    println!("Parsing the following markdown string:\n{}", markdown_input);
6
7    // Set up options and parser. Strikethroughs are not part of the CommonMark standard
8    // and we therefore must enable it explicitly.
9    let mut options = Options::empty();
10    options.insert(Options::ENABLE_STRIKETHROUGH);
11    let parser = Parser::new_ext(markdown_input, options);
12
13    // Write to String buffer.
14    let mut html_output: String = String::with_capacity(markdown_input.len() * 3 / 2);
15    html::push_html(&mut html_output, parser);
16
17    // Check that the output is what we expected.
18    let expected_html: &str =
19        "<p>Hello world, this is a <del>complicated</del> <em>very simple</em> example.</p>\n";
20    assert_eq!(expected_html, &html_output);
21
22    // Write result to stdout.
23    println!("\nHTML output:\n{}", &html_output);
24}
More examples
Hide additional examples
examples/event-filter.rs (line 11)
5fn main() {
6    let markdown_input: &str = "This is Peter on ![holiday in Greece](pearl_beach.jpg).";
7    println!("Parsing the following markdown string:\n{}", markdown_input);
8
9    // Set up parser. We can treat is as any other iterator. We replace Peter by John
10    // and image by its alt text.
11    let parser = Parser::new_ext(markdown_input, Options::empty())
12        .map(|event| match event {
13            Event::Text(text) => Event::Text(text.replace("Peter", "John").into()),
14            _ => event,
15        })
16        .filter(|event| match event {
17            Event::Start(Tag::Image { .. }) | Event::End(TagEnd::Image) => false,
18            _ => true,
19        });
20
21    // Write to anything implementing the `Write` trait. This could also be a file
22    // or network socket.
23    let stdout = std::io::stdout();
24    let mut handle = stdout.lock();
25    handle.write_all(b"\nHTML output:\n").unwrap();
26    html::write_html_io(&mut handle, parser).unwrap();
27}
examples/normalize-wikilink.rs (line 14)
7fn main() {
8    let markdown_input: &str = r#"
9Example provided by [[https://example.org/]].
10Some people might prefer the wikilink syntax for autolinks.
11
12Wanna go for a [[Wiki Walk]]?"#;
13
14    let parser = Parser::new_ext(markdown_input, Options::ENABLE_WIKILINKS).map(|event| {
15        if let Event::Start(Tag::Link {
16            link_type: LinkType::WikiLink { has_pothole },
17            dest_url,
18            title,
19            id,
20        }) = event
21        {
22            let new_link = normalize_wikilink(dest_url);
23            Event::Start(Tag::Link {
24                link_type: LinkType::WikiLink { has_pothole },
25                dest_url: new_link,
26                title,
27                id,
28            })
29        } else {
30            event
31        }
32    });
33
34    // Write to anything implementing the `Write` trait. This could also be a file
35    // or network socket.
36    let stdout = std::io::stdout();
37    let mut handle = stdout.lock();
38    handle.write_all(b"\nHTML output:\n").unwrap();
39    html::write_html_io(&mut handle, parser).unwrap();
40}
examples/parser-map-tag-print.rs (line 45)
3fn main() {
4    let markdown_input = concat!(
5        "# My Heading\n",
6        "\n",
7        "My paragraph.\n",
8        "\n",
9        "* a\n",
10        "* b\n",
11        "* c\n",
12        "\n",
13        "1. d\n",
14        "2. e\n",
15        "3. f\n",
16        "\n",
17        "> my block quote\n",
18        "\n",
19        "```\n",
20        "my code block\n",
21        "```\n",
22        "\n",
23        "*emphasis*\n",
24        "**strong**\n",
25        "~~strikethrough~~\n",
26        "[My Link](http://example.com)\n",
27        "![My Image](http://example.com/image.jpg)\n",
28        "\n",
29        "| a | b |\n",
30        "| - | - |\n",
31        "| c | d |\n",
32        "\n",
33        "hello[^1]\n",
34        "[^1]: my footnote\n",
35    );
36    println!(
37        "\nParsing the following markdown string:\n{}\n",
38        markdown_input
39    );
40
41    // Set up the parser. We can treat is as any other iterator.
42    // For each event, we print its details, such as the tag or string.
43    // This filter simply returns the same event without any changes;
44    // you can compare the `event-filter` example which alters the output.
45    let parser = Parser::new_ext(markdown_input, Options::all()).map(|event| {
46        match &event {
47            Event::Start(tag) => match tag {
48                Tag::HtmlBlock => println!("HtmlBlock"),
49                Tag::Heading {
50                    level,
51                    id,
52                    classes,
53                    attrs,
54                } => println!(
55                    "Heading heading_level: {} fragment identifier: {:?} classes: {:?} attrs: {:?}",
56                    level, id, classes, attrs
57                ),
58                Tag::Paragraph => println!("Paragraph"),
59                Tag::List(ordered_list_first_item_number) => println!(
60                    "List ordered_list_first_item_number: {:?}",
61                    ordered_list_first_item_number
62                ),
63                Tag::DefinitionList => println!("Definition list"),
64                Tag::DefinitionListTitle => println!("Definition title (definition list item)"),
65                Tag::DefinitionListDefinition => println!("Definition (definition list item)"),
66                Tag::Item => println!("Item (this is a list item)"),
67                Tag::Emphasis => println!("Emphasis (this is a span tag)"),
68                Tag::Superscript => println!("Superscript (this is a span tag)"),
69                Tag::Subscript => println!("Subscript (this is a span tag)"),
70                Tag::Strong => println!("Strong (this is a span tag)"),
71                Tag::Strikethrough => println!("Strikethrough (this is a span tag)"),
72                Tag::BlockQuote(kind) => println!("BlockQuote ({:?})", kind),
73                Tag::CodeBlock(code_block_kind) => {
74                    println!("CodeBlock code_block_kind: {:?}", code_block_kind)
75                }
76                Tag::Link {
77                    link_type,
78                    dest_url,
79                    title,
80                    id,
81                } => println!(
82                    "Link link_type: {:?} url: {} title: {} id: {}",
83                    link_type, dest_url, title, id
84                ),
85                Tag::Image {
86                    link_type,
87                    dest_url,
88                    title,
89                    id,
90                } => println!(
91                    "Image link_type: {:?} url: {} title: {} id: {}",
92                    link_type, dest_url, title, id
93                ),
94                Tag::Table(column_text_alignment_list) => println!(
95                    "Table column_text_alignment_list: {:?}",
96                    column_text_alignment_list
97                ),
98                Tag::TableHead => println!("TableHead (contains TableRow tags"),
99                Tag::TableRow => println!("TableRow (contains TableCell tags)"),
100                Tag::TableCell => println!("TableCell (contains inline tags)"),
101                Tag::FootnoteDefinition(label) => println!("FootnoteDefinition label: {}", label),
102                Tag::MetadataBlock(kind) => println!("MetadataBlock: {:?}", kind),
103            },
104            _ => (),
105        };
106        event
107    });
108
109    let mut html_output = String::new();
110    pulldown_cmark::html::push_html(&mut html_output, parser);
111    println!("\nHTML output:\n{}\n", &html_output);
112}
examples/footnote-rewrite.rs (line 18)
8fn main() {
9    let markdown_input: &str = "This is an [^a] footnote [^a].\n\n[^a]: footnote contents";
10    println!("Parsing the following markdown string:\n{}", markdown_input);
11
12    // To generate this style, you have to collect the footnotes at the end, while parsing.
13    // You also need to count usages.
14    let mut footnotes = Vec::new();
15    let mut in_footnote = Vec::new();
16    let mut footnote_numbers = HashMap::new();
17    // ENABLE_FOOTNOTES is used in this example, but ENABLE_OLD_FOOTNOTES would work, too.
18    let parser = Parser::new_ext(markdown_input, Options::ENABLE_FOOTNOTES)
19        .filter_map(|event| {
20            match event {
21                Event::Start(Tag::FootnoteDefinition(_)) => {
22                    in_footnote.push(vec![event]);
23                    None
24                }
25                Event::End(TagEnd::FootnoteDefinition) => {
26                    let mut f = in_footnote.pop().unwrap();
27                    f.push(event);
28                    footnotes.push(f);
29                    None
30                }
31                Event::FootnoteReference(name) => {
32                    let n = footnote_numbers.len() + 1;
33                    let (n, nr) = footnote_numbers.entry(name.clone()).or_insert((n, 0usize));
34                    *nr += 1;
35                    let html = Event::Html(format!(r##"<sup class="footnote-reference" id="fr-{name}-{nr}"><a href="#fn-{name}">[{n}]</a></sup>"##).into());
36                    if in_footnote.is_empty() {
37                        Some(html)
38                    } else {
39                        in_footnote.last_mut().unwrap().push(html);
40                        None
41                    }
42                }
43                _ if !in_footnote.is_empty() => {
44                    in_footnote.last_mut().unwrap().push(event);
45                    None
46                }
47                _ => Some(event),
48            }
49        });
50
51    // Write to anything implementing the `Write` trait. This could also be a file
52    // or network socket.
53    let stdout = std::io::stdout();
54    let mut handle = stdout.lock();
55    handle.write_all(b"\nHTML output:\n").unwrap();
56    html::write_html_io(&mut handle, parser).unwrap();
57
58    // To make the footnotes look right, we need to sort them by their appearance order, not by
59    // the in-tree order of their actual definitions. Unused items are omitted entirely.
60    //
61    // For example, this code:
62    //
63    //     test [^1] [^2]
64    //     [^2]: second used, first defined
65    //     [^1]: test
66    //
67    // Gets rendered like *this* if you copy it into a GitHub comment box:
68    //
69    //     <p>test <sup>[1]</sup> <sup>[2]</sup></p>
70    //     <hr>
71    //     <ol>
72    //     <li>test ↩</li>
73    //     <li>second used, first defined ↩</li>
74    //     </ol>
75    if !footnotes.is_empty() {
76        footnotes.retain(|f| match f.first() {
77            Some(Event::Start(Tag::FootnoteDefinition(name))) => {
78                footnote_numbers.get(name).unwrap_or(&(0, 0)).1 != 0
79            }
80            _ => false,
81        });
82        footnotes.sort_by_cached_key(|f| match f.first() {
83            Some(Event::Start(Tag::FootnoteDefinition(name))) => {
84                footnote_numbers.get(name).unwrap_or(&(0, 0)).0
85            }
86            _ => unreachable!(),
87        });
88        handle
89            .write_all(b"<hr><ol class=\"footnotes-list\">\n")
90            .unwrap();
91        html::write_html_io(
92            &mut handle,
93            footnotes.into_iter().flat_map(|fl| {
94                // To write backrefs, the name needs kept until the end of the footnote definition.
95                let mut name = CowStr::from("");
96                // Backrefs are included in the final paragraph of the footnote, if it's normal text.
97                // For example, this DOM can be produced:
98                //
99                // Markdown:
100                //
101                //     five [^feet].
102                //
103                //     [^feet]:
104                //         A foot is defined, in this case, as 0.3048 m.
105                //
106                //         Historically, the foot has not been defined this way, corresponding to many
107                //         subtly different units depending on the location.
108                //
109                // HTML:
110                //
111                //     <p>five <sup class="footnote-reference" id="fr-feet-1"><a href="#fn-feet">[1]</a></sup>.</p>
112                //
113                //     <ol class="footnotes-list">
114                //     <li id="fn-feet">
115                //     <p>A foot is defined, in this case, as 0.3048 m.</p>
116                //     <p>Historically, the foot has not been defined this way, corresponding to many
117                //     subtly different units depending on the location. <a href="#fr-feet-1">↩</a></p>
118                //     </li>
119                //     </ol>
120                //
121                // This is mostly a visual hack, so that footnotes use less vertical space.
122                //
123                // If there is no final paragraph, such as a tabular, list, or image footnote, it gets
124                // pushed after the last tag instead.
125                let mut has_written_backrefs = false;
126                let fl_len = fl.len();
127                let footnote_numbers = &footnote_numbers;
128                fl.into_iter().enumerate().map(move |(i, f)| match f {
129                    Event::Start(Tag::FootnoteDefinition(current_name)) => {
130                        name = current_name;
131                        has_written_backrefs = false;
132                        Event::Html(format!(r##"<li id="fn-{name}">"##).into())
133                    }
134                    Event::End(TagEnd::FootnoteDefinition) | Event::End(TagEnd::Paragraph)
135                        if !has_written_backrefs && i >= fl_len - 2 =>
136                    {
137                        let usage_count = footnote_numbers.get(&name).unwrap().1;
138                        let mut end = String::with_capacity(
139                            name.len() + (r##" <a href="#fr--1">↩</a></li>"##.len() * usage_count),
140                        );
141                        for usage in 1..=usage_count {
142                            if usage == 1 {
143                                write!(&mut end, r##" <a href="#fr-{name}-{usage}">↩</a>"##)
144                                    .unwrap();
145                            } else {
146                                write!(&mut end, r##" <a href="#fr-{name}-{usage}">↩{usage}</a>"##)
147                                    .unwrap();
148                            }
149                        }
150                        has_written_backrefs = true;
151                        if f == Event::End(TagEnd::FootnoteDefinition) {
152                            end.push_str("</li>\n");
153                        } else {
154                            end.push_str("</p>\n");
155                        }
156                        Event::Html(end.into())
157                    }
158                    Event::End(TagEnd::FootnoteDefinition) => Event::Html("</li>\n".into()),
159                    Event::FootnoteReference(_) => unreachable!("converted to HTML earlier"),
160                    f => f,
161                })
162            }),
163        )
164        .unwrap();
165        handle.write_all(b"</ol>\n").unwrap();
166    }
167}
Source§

impl<'input, F: BrokenLinkCallback<'input>> Parser<'input, F>

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)
3fn main() {
4    let input: &str = "Hello world, check out [my website][].";
5    println!("Parsing the following markdown string:\n{}", input);
6
7    // Setup callback that sets the URL and title when it encounters
8    // a reference to our home page.
9    let callback = |broken_link: BrokenLink| {
10        if broken_link.reference.as_ref() == "my website" {
11            println!(
12                "Replacing the markdown `{}` of type {:?} with a working link",
13                &input[broken_link.span], broken_link.link_type,
14            );
15            Some(("http://example.com".into(), "my example website".into()))
16        } else {
17            None
18        }
19    };
20
21    // Create a parser with our callback function for broken links.
22    let parser = Parser::new_with_broken_link_callback(input, Options::empty(), Some(callback));
23
24    // Write to String buffer.
25    let mut html_output: String = String::with_capacity(input.len() * 3 / 2);
26    html::push_html(&mut html_output, parser);
27
28    // Check that the output is what we expected.
29    let expected_html: &str =
30        "<p>Hello world, check out <a href=\"http://example.com\" title=\"my example website\">my website</a>.</p>\n";
31    assert_eq!(expected_html, &html_output);
32
33    // Write result to stdout.
34    println!("\nHTML output:\n{}", &html_output);
35}
Source

pub fn reference_definitions(&self) -> &RefDefs<'_>

Returns a reference to the internal RefDefs object, which provides access to the internal map of reference definitions.

Source

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<'input, F> Debug for Parser<'input, F>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a, F: BrokenLinkCallback<'a>> Iterator for Parser<'a, F>

Source§

type Item = Event<'a>

The type of the elements being iterated over.
Source§

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,

🔬This is a nightly-only experimental API. (iter_next_chunk)
Advances the iterator and returns an array containing the next N values. Read more
1.0.0 · Source§

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) -> usize
where 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,

Consumes the iterator, returning the last element. Read more
Source§

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 more
1.0.0 · Source§

fn nth(&mut self, n: usize) -> Option<Self::Item>

Returns the nth element of the iterator. Read more
1.28.0 · Source§

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>
where Self: Sized, U: IntoIterator<Item = Self::Item>,

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,

‘Zips up’ two iterators into a single iterator of pairs. Read more
Source§

fn intersperse(self, separator: Self::Item) -> Intersperse<Self>
where Self: Sized, Self::Item: Clone,

🔬This is a nightly-only experimental API. (iter_intersperse)
Creates a new iterator which places a copy of separator between adjacent items of the original iterator. Read more
Source§

fn intersperse_with<G>(self, separator: G) -> IntersperseWith<Self, G>
where Self: Sized, G: FnMut() -> Self::Item,

🔬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 more
1.0.0 · Source§

fn map<B, F>(self, f: F) -> Map<Self, F>
where Self: Sized, F: FnMut(Self::Item) -> B,

Takes a closure and creates an iterator which calls that closure on each element. Read more
1.21.0 · Source§

fn for_each<F>(self, f: F)
where Self: Sized, F: FnMut(Self::Item),

Calls a closure on each element of an iterator. Read more
1.0.0 · Source§

fn filter<P>(self, predicate: P) -> Filter<Self, P>
where Self: Sized, P: FnMut(&Self::Item) -> bool,

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>
where Self: Sized, F: FnMut(Self::Item) -> Option<B>,

Creates an iterator that both filters and maps. Read more
1.0.0 · Source§

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 peekable(self) -> Peekable<Self>
where Self: Sized,

Creates an iterator which can use the peek and peek_mut methods to look at the next element of the iterator without consuming it. See their documentation for more information. Read more
1.0.0 · Source§

fn skip_while<P>(self, predicate: P) -> SkipWhile<Self, P>
where Self: Sized, P: FnMut(&Self::Item) -> bool,

Creates an iterator that skips elements based on a predicate. Read more
1.0.0 · Source§

fn take_while<P>(self, predicate: P) -> TakeWhile<Self, P>
where Self: Sized, P: FnMut(&Self::Item) -> bool,

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>
where Self: Sized, P: FnMut(Self::Item) -> Option<B>,

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,

Creates an iterator that skips the first n elements. Read more
1.0.0 · Source§

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 more
1.0.0 · Source§

fn scan<St, B, F>(self, initial_state: St, f: F) -> Scan<Self, St, F>
where Self: Sized, F: FnMut(&mut St, Self::Item) -> Option<B>,

An iterator adapter which, like fold, holds internal state, but unlike fold, produces a new iterator. Read more
1.0.0 · Source§

fn flat_map<U, F>(self, f: F) -> FlatMap<Self, U, F>
where Self: Sized, U: IntoIterator, F: FnMut(Self::Item) -> U,

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>
where Self: Sized, F: FnMut(&[Self::Item; N]) -> R,

🔬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 more
1.0.0 · Source§

fn fuse(self) -> Fuse<Self>
where Self: Sized,

Creates an iterator which ends after the first None. Read more
1.0.0 · Source§

fn inspect<F>(self, f: F) -> Inspect<Self, F>
where Self: Sized, F: FnMut(&Self::Item),

Does something with each element of an iterator, passing the value on. Read more
1.0.0 · Source§

fn by_ref(&mut self) -> &mut Self
where Self: Sized,

Creates a “by reference” adapter for this instance of Iterator. Read more
1.0.0 · Source§

fn collect<B>(self) -> B
where B: FromIterator<Self::Item>, Self: Sized,

Transforms an iterator into a collection. Read more
Source§

fn collect_into<E>(self, collection: &mut E) -> &mut E
where E: Extend<Self::Item>, Self: Sized,

🔬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)
where Self: Sized, B: Default + Extend<Self::Item>, F: FnMut(&Self::Item) -> bool,

Consumes an iterator, creating two collections from it. Read more
Source§

fn is_partitioned<P>(self, predicate: P) -> bool
where Self: Sized, P: FnMut(Self::Item) -> 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 more
1.27.0 · Source§

fn try_fold<B, F, R>(&mut self, init: B, f: F) -> R
where Self: Sized, F: FnMut(B, Self::Item) -> R, R: Try<Output = B>,

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
where Self: Sized, F: FnMut(Self::Item) -> R, R: Try<Output = ()>,

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
where Self: Sized, F: FnMut(B, Self::Item) -> 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>
where Self: Sized, F: FnMut(Self::Item, Self::Item) -> 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
where Self: Sized, R: Try<Output = Self::Item>, <R as Try>::Residual: Residual<Option<Self::Item>>,

🔬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
where Self: Sized, F: FnMut(Self::Item) -> 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
where Self: Sized, F: FnMut(Self::Item) -> 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>
where Self: Sized, P: FnMut(&Self::Item) -> bool,

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>
where Self: Sized, F: FnMut(Self::Item) -> 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
where Self: Sized, R: Try<Output = bool>, <R as Try>::Residual: Residual<Option<Self::Item>>,

🔬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>
where Self: Sized, P: FnMut(Self::Item) -> bool,

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>
where B: Ord, Self: Sized, F: FnMut(&Self::Item) -> B,

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>
where Self: Sized, F: FnMut(&Self::Item, &Self::Item) -> Ordering,

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>
where B: Ord, Self: Sized, F: FnMut(&Self::Item) -> B,

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>
where Self: Sized, F: FnMut(&Self::Item, &Self::Item) -> Ordering,

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)
where FromA: Default + Extend<A>, FromB: Default + Extend<B>, Self: Sized + Iterator<Item = (A, B)>,

Converts an iterator of pairs into a pair of containers. Read more
1.36.0 · Source§

fn copied<'a, T>(self) -> Copied<Self>
where T: 'a + Copy, Self: Sized + Iterator<Item = &'a T>,

Creates an iterator which copies all of its elements. Read more
1.0.0 · Source§

fn cloned<'a, T>(self) -> Cloned<Self>
where T: 'a + Clone, Self: Sized + Iterator<Item = &'a T>,

Creates an iterator which clones all of its elements. Read more
Source§

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 more
1.11.0 · Source§

fn sum<S>(self) -> S
where Self: Sized, S: Sum<Self::Item>,

Sums the elements of an iterator. Read more
1.11.0 · Source§

fn product<P>(self) -> P
where Self: Sized, P: Product<Self::Item>,

Iterates over the entire iterator, multiplying all the elements Read more
Source§

fn cmp_by<I, F>(self, other: I, cmp: F) -> Ordering
where Self: Sized, I: IntoIterator, F: FnMut(Self::Item, <I as IntoIterator>::Item) -> 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 more
1.5.0 · Source§

fn partial_cmp<I>(self, other: I) -> Option<Ordering>
where I: IntoIterator, Self::Item: PartialOrd<<I as IntoIterator>::Item>, Self: Sized,

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 more
Source§

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 more
1.5.0 · Source§

fn eq<I>(self, other: I) -> bool
where I: IntoIterator, Self::Item: PartialEq<<I as IntoIterator>::Item>, Self: Sized,

Determines if the elements of this Iterator are equal to those of another. Read more
Source§

fn eq_by<I, F>(self, other: I, eq: F) -> bool
where Self: Sized, I: IntoIterator, F: FnMut(Self::Item, <I as IntoIterator>::Item) -> bool,

🔬This is a nightly-only experimental API. (iter_order_by)
Determines if the elements of this Iterator are equal to those of another with respect to the specified equality function. Read more
1.5.0 · Source§

fn ne<I>(self, other: I) -> bool
where I: IntoIterator, Self::Item: PartialEq<<I as IntoIterator>::Item>, Self: Sized,

Determines if the elements of this Iterator are not equal to those of another. Read more
1.5.0 · Source§

fn lt<I>(self, other: I) -> bool
where I: IntoIterator, Self::Item: PartialOrd<<I as IntoIterator>::Item>, Self: Sized,

Determines if the elements of this Iterator are lexicographically less than those of another. Read more
1.5.0 · Source§

fn le<I>(self, other: I) -> bool
where I: IntoIterator, Self::Item: PartialOrd<<I as IntoIterator>::Item>, Self: Sized,

Determines if the elements of this Iterator are lexicographically less or equal to those of another. Read more
1.5.0 · Source§

fn gt<I>(self, other: I) -> bool
where I: IntoIterator, Self::Item: PartialOrd<<I as IntoIterator>::Item>, Self: Sized,

Determines if the elements of this Iterator are lexicographically greater than those of another. Read more
1.5.0 · Source§

fn ge<I>(self, other: I) -> bool
where I: IntoIterator, Self::Item: PartialOrd<<I as IntoIterator>::Item>, Self: Sized,

Determines if the elements of this Iterator are lexicographically greater than or equal to those of another. Read more
1.82.0 · Source§

fn is_sorted_by<F>(self, compare: F) -> bool
where Self: Sized, F: FnMut(&Self::Item, &Self::Item) -> 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
where Self: Sized, F: FnMut(Self::Item) -> K, K: PartialOrd,

Checks if the elements of this iterator are sorted using the given key extraction function. Read more
Source§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<I> IntoIterator for I
where I: Iterator,

Source§

type Item = <I as Iterator>::Item

The type of the elements being iterated over.
Source§

type IntoIter = I

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> I

Creates an iterator from a value. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.