[][src]Struct rfind_url::Parser

pub struct Parser { /* fields omitted */ }

State machine for finding URLs.

The URL parser takes characters of a string in reverse order and returns the length of the URL whenever finding one.

Methods

impl Parser[src]

pub fn new() -> Self[src]

Creates a new URL parser.

Examples

use rfind_url::Parser;

let mut parser = Parser::new();

pub fn advance(&mut self, c: char) -> ParserState[src]

Advances the parser by one character.

Examples

use rfind_url::{Parser, ParserState};

let mut parser = Parser::new();

// Current character is not part of a URL
assert_eq!(parser.advance(' '), ParserState::NoUrl);

// URLs are only returned once they are complete
for c in "ttps://example.org".chars().rev() {
    assert_eq!(parser.advance(c), ParserState::MaybeUrl);
}

// Parser has detected a URL spanning the last 19 characters
assert_eq!(parser.advance('h'), ParserState::Url(19));

pub fn reset(&mut self)[src]

Reset the parser to its initial state.

Examples

use rfind_url::{Parser, ParserState};

let mut parser = Parser::new();

// Feed some data into the parser
for c in "ttps://example.org".chars().rev() {
    assert_eq!(parser.advance(c), ParserState::MaybeUrl);
}

// Reset to initial state, ignoring the previously received characters
parser.reset();

// No URL detected, since the state has been reset
assert_eq!(parser.advance('h'), ParserState::MaybeUrl);

Trait Implementations

impl Default for Parser[src]

Auto Trait Implementations

impl Send for Parser

impl Unpin for Parser

impl Sync for Parser

impl UnwindSafe for Parser

impl RefUnwindSafe for Parser

Blanket Implementations

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

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

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.

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

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

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