Struct Parser

Source
pub struct Parser { /* private fields */ }

Implementationsยง

Sourceยง

impl Parser

Source

pub fn anchor<'a>(&self, input: &'a str) -> Option<&'a str>

Extract the anchor from the url.

ยงExample
use url_parse::core::Parser;
let input = "https://www.example.co.uk:443/blog/article/search?docid=720&hl=en#dayone";
let result = Parser::new(None).anchor(input).unwrap();
assert_eq!(result, "dayone");
Sourceยง

impl Parser

Source

pub fn domain<'a>(&self, input: &'a str) -> Domain<'a>

Extract the domain fields from the url.

ยงExample
use url_parse::core::Parser;
use url_parse::core::global::Domain;
let input = "https://www.example.com:443/blog/article/search?docid=720&hl=en#dayone";
let expected = Domain {
    subdomain: Some("www"),
    domain: Some("example"),
    top_level_domain: Some("com"),
};
let result = Parser::new(None).domain(input);
assert_eq!(result, expected);
Sourceยง

impl Parser

Source

pub fn login<'a>(&self, input: &'a str) -> (Option<&'a str>, Option<&'a str>)

Extract the domain fields from the url.

ยงExample
use url_parse::core::Parser;
let input = "https://user:pass@www.example.co.uk";
let expected = (Some("user"), Some("pass"));
let result = Parser::new(None).login(input);
assert_eq!(result, expected);
Sourceยง

impl Parser

Source

pub fn path<'a>(&self, input: &'a str) -> Option<Vec<&'a str>>

Extract the path as a vector from the url.

ยงExample
use url_parse::core::Parser;
let input = "https://www.example.co.uk:443/blog/article/search?docid=720&hl=en#dayone";
let result = Parser::new(None).path(input).unwrap();
let expected = vec!["blog", "article", "search"];
assert_eq!(result, expected);
Sourceยง

impl Parser

Source

pub fn port(&self, input: &str) -> Option<u32>

Extract the port from the url. If no port is present, it will be deduced from the scheme. The default scheme provides well-known ports. The user can specify new schemes when constructing the Parser object with new().

ยงExample
use url_parse::core::Parser;
let input = "https://www.example.co.uk:443/blog/article/search?docid=720&hl=en#dayone";
let port = Parser::new(None).port(input);
assert_eq!(port.unwrap(), 443);
Sourceยง

impl Parser

Source

pub fn query<'a>(&self, input: &'a str) -> Option<&'a str>

Extract the query from the url.

ยงExample
use url_parse::core::Parser;
let input = "https://www.example.co.uk:443/blog/article/search?docid=720&hl=en#dayone";
let result = Parser::new(None).query(input).unwrap();
assert_eq!(result, "docid=720&hl=en");
Sourceยง

impl Parser

Source

pub fn scheme<'a>(&self, input: &'a str) -> Option<(&'a str, SchemeSeparator)>

Extract the query from the url.

ยงExample
use url_parse::core::Parser;
use url_parse::core::scheme_separator::SchemeSeparator;
let input = "https://www.example.co.uk:443/blog/article/search?docid=720&hl=en#dayone";
let scheme = Parser::new(None).scheme(input);
assert_eq!(scheme.unwrap(), ("https",  SchemeSeparator::ColonSlashSlash));

Schemas can also have a simple colon instead ot the โ€œ://โ€ pattern.

ยงExample
use url_parse::core::Parser;
use url_parse::core::scheme_separator::SchemeSeparator;
let input = "https:www.example.co.uk:443/blog/article/search?docid=720&hl=en#dayone";
let scheme = Parser::new(None).scheme(input);
assert_eq!(scheme.unwrap(), ("https",  SchemeSeparator::Colon));
Sourceยง

impl Parser

Source

pub fn new( port_mappings: Option<HashMap<&'static str, (u32, &'static str)>>, ) -> Self

Create a new parser object. Optionally pass in a hash map of default port mappings. Its fields are then directly accessible.

ยงExample
use url_parse::core::Parser;
let parser = Parser::new(None);
Source

pub fn parse(&self, url: &str) -> Result<Url, ParseError>

Create a new parser object with Parser::new(). You can then use parser.parse(url) which will return a public Url parsed structure back. Its fields are then directly accessible.

ยงExample
use url_parse::core::Parser;
use url_parse::url::Url;
let input = "https://user:pass@www.example.co.uk:443/blog/article/search?docid=720&hl=en#dayone";
let result = Parser::new(None).parse(input).unwrap();
assert_eq!(
    result,
    Url {
        scheme: Some("https".to_string()),
        user_pass: (Some("user".to_string()), Some("pass".to_string())),
        subdomain: Some("www".to_string()),
        domain: Some("example.co".to_string()),
        top_level_domain: Some("uk".to_string()),
        port: Some(443),
        path: Some(vec![
            "blog".to_string(),
            "article".to_string(),
            "search".to_string(),
        ]),
        query: Some("docid=720&hl=en#dayone".to_string()),
        anchor: Some("dayone".to_string()),
    }
)

Auto Trait Implementationsยง

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<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.