Struct parse_hyperlinks::iterator::Hyperlink[][src]

pub struct Hyperlink<'a> { /* fields omitted */ }

Iterator over all the hyperlinks in the input text. This struct holds the iterator’s state and an advancing pointer into the input text. The iterator’s next() method returns a tuple with 2 tuples inside: Some(((input_split)(link_content))).

Each tuple has the following parts:

  • input_split = (skipped_characters, consumed_characters, remaining_characters)
  • link_content = (link_text, link_destination, link_title)

Input split

use parse_hyperlinks::iterator::Hyperlink;
use std::borrow::Cow;

let i = "abc[text0](dest0)efg[text1](dest1)hij";

let mut iter = Hyperlink::new(i, false);
assert_eq!(iter.next().unwrap().0, ("abc", "[text0](dest0)", "efg[text1](dest1)hij"));
assert_eq!(iter.next().unwrap().0, ("efg", "[text1](dest1)", "hij"));
assert_eq!(iter.next(), None);

Link content

Markdown

use parse_hyperlinks::iterator::Hyperlink;
use std::borrow::Cow;

let i = r#"abc[text0](dest0 "title0")abc
abc[text1][label1]abc
abc[text2](dest2 "title2")
[text3]: dest3 "title3"
[label1]: dest1 "title1"
abc[text3]abc
"#;

let mut iter = Hyperlink::new(i, false);
assert_eq!(iter.next().unwrap().1, (Cow::from("text0"), Cow::from("dest0"), Cow::from("title0")));
assert_eq!(iter.next().unwrap().1, (Cow::from("text1"), Cow::from("dest1"), Cow::from("title1")));
assert_eq!(iter.next().unwrap().1, (Cow::from("text2"), Cow::from("dest2"), Cow::from("title2")));
assert_eq!(iter.next().unwrap().1, (Cow::from("text3"), Cow::from("dest3"), Cow::from("title3")));
assert_eq!(iter.next(), None);

reStructuredText

use parse_hyperlinks::iterator::Hyperlink;
use std::borrow::Cow;

let i = r#"
abc `text1 <label1_>`_abc
abc text2_ abc
abc text3__ abc
abc text_label4_ abc
abc text5__ abc
.. _label1: dest1
.. _text2: dest2
.. __: dest3
__ dest5
"#;

let mut iter = Hyperlink::new(i, false);
assert_eq!(iter.next().unwrap().1, (Cow::from("text1"), Cow::from("dest1"), Cow::from("")));
assert_eq!(iter.next().unwrap().1, (Cow::from("text2"), Cow::from("dest2"), Cow::from("")));
assert_eq!(iter.next().unwrap().1, (Cow::from("text3"), Cow::from("dest3"), Cow::from("")));
assert_eq!(iter.next().unwrap().1, (Cow::from("text5"), Cow::from("dest5"), Cow::from("")));
assert_eq!(iter.next(), None);

Asciidoc

use parse_hyperlinks::iterator::Hyperlink;
use std::borrow::Cow;

let i = r#"abc
abc https://dest0[text0]abc
abc link:https://dest1[text1]abc
abc {label2}[text2]abc
abc {label3}abc
:label2: https://dest2
:label3: https://dest3
"#;

let mut iter = Hyperlink::new(i, false);
assert_eq!(iter.next().unwrap().1, (Cow::from("text0"), Cow::from("https://dest0"), Cow::from("")));
assert_eq!(iter.next().unwrap().1, (Cow::from("text1"), Cow::from("https://dest1"), Cow::from("")));
assert_eq!(iter.next().unwrap().1, (Cow::from("text2"), Cow::from("https://dest2"), Cow::from("")));
assert_eq!(iter.next().unwrap().1, (Cow::from("https://dest3"), Cow::from("https://dest3"), Cow::from("")));
assert_eq!(iter.next(), None);

HTML

use parse_hyperlinks::iterator::Hyperlink;
use std::borrow::Cow;

let i = r#"abc<a href="dest1" title="title1">text1</a>abc
abc<a href="dest2" title="title2">text2</a>abc
"#;

let mut iter = Hyperlink::new(i, false);
assert_eq!(iter.next().unwrap().1, (Cow::from("text1"), Cow::from("dest1"), Cow::from("title1")));
assert_eq!(iter.next().unwrap().1, (Cow::from("text2"), Cow::from("dest2"), Cow::from("title2")));
assert_eq!(iter.next(), None);

Implementations

impl<'a> Hyperlink<'a>[src]

Constructor for the Hyperlink struct.

pub fn new(input: &'a str, render_label: bool) -> Self[src]

Constructor for the iterator. input is the text with hyperlinks to be extracted.

Optional rendering of Label2Dest link reference definitions

By default Label2Dest link reference definitions are not rendered:

use parse_hyperlinks::iterator::Hyperlink;
use std::borrow::Cow;

let i = r#"abc[text1][label1]abc
[label1]: dest1 "title1"
"#;

let mut iter = Hyperlink::new(i, false);
assert_eq!(iter.next().unwrap().1, (Cow::from("text1"), Cow::from("dest1"), Cow::from("title1")));
assert_eq!(iter.next(), None);

If the internal variable render_label is true, then Label2Dest link reference definitions are rendered like inline links: the full Label2Dest link reference definition’s source will appear as link text and its destination as link destination. To enable this feature, construct Hyperlink with the second positional parameter set to true, e.g. Hyperlink::new(i, true).

use parse_hyperlinks::iterator::Hyperlink;
use std::borrow::Cow;

let i = r#"abc[text1][label1]abc
[label1]: dest1 "title1"
"#;

let mut iter = Hyperlink::new(i, true);
assert_eq!(iter.next().unwrap().1, (Cow::from("text1"), Cow::from("dest1"), Cow::from("title1")));
assert_eq!(iter.next().unwrap().1, (Cow::from("[label1]: dest1 \"title1\""), Cow::from("dest1"), Cow::from("title1")));
assert_eq!(iter.next(), None);

Trait Implementations

impl<'a> Debug for Hyperlink<'a>[src]

impl<'a> Iterator for Hyperlink<'a>[src]

Iterator over the hyperlinks (with markup) in the input-text. The iterator’s next() method returns a tuple with 2 tuples inside:

  • Some(((input_split)(link_content)))

Each tuple has the following parts:

  • input_split = (skipped_characters, consumed_characters, remaining_characters)
  • link_content = (link_text, link_destination, link_title)

type Item = ((&'a str, &'a str, &'a str), (Cow<'a, str>, Cow<'a, str>, Cow<'a, str>))

The type of the elements being iterated over.

fn next(&mut self) -> Option<Self::Item>[src]

The iterator operates in 2 modes:

  1. Status::DirectSearch: This is the starting state. So far the iterator has only encountered inline links so far. Nothing needs to be resolved and the next method can output the link immediately. The next() method outputs directly the result from the parser parser::take_link().
  2. Status::ResolvedLinks: as soon as the iterator encounters some reference link, e.g. Text2label, Label2Dest or Label2Label link, it switches into Status::ResolvedLinks mode. The transition happens as follows:
    1. The next() method consumes all the remaining input and calls the populate_collection(), resolve_label2label_references() and resolve_text2label_references() methods. From now on,
    2. the next() method outputs and deletes HyperlinkCollection::Dest2Text_label[0]. Not resolved Text2Label are ignored.

impl<'a> PartialEq<Hyperlink<'a>> for Hyperlink<'a>[src]

impl<'a> StructuralPartialEq for Hyperlink<'a>[src]

Auto Trait Implementations

impl<'a> RefUnwindSafe for Hyperlink<'a>

impl<'a> Send for Hyperlink<'a>

impl<'a> Sync for Hyperlink<'a>

impl<'a> Unpin for Hyperlink<'a>

impl<'a> UnwindSafe for Hyperlink<'a>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Conv for T

impl<T> Conv for T

impl<T> FmtForward for T

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<I> IntoIterator for I where
    I: Iterator
[src]

type Item = <I as Iterator>::Item

The type of the elements being iterated over.

type IntoIter = I

Which kind of iterator are we turning this into?

impl<T> Pipe for T where
    T: ?Sized

impl<T> Pipe for T

impl<T> PipeAsRef for T

impl<T> PipeBorrow for T

impl<T> PipeDeref for T

impl<T> PipeRef for T

impl<T> Tap for T

impl<T> Tap for T

impl<T, U> TapAsRef<U> for T where
    U: ?Sized

impl<T, U> TapBorrow<U> for T where
    U: ?Sized

impl<T> TapDeref for T

impl<T> TryConv for T

impl<T> TryConv for T

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.