[−][src]Struct rfind_url::Parser
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]
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
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> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,