Struct Url

Source
pub struct Url {
    pub scheme: Option<String>,
    pub user_pass: (Option<String>, Option<String>),
    pub subdomain: Option<String>,
    pub domain: Option<String>,
    pub top_level_domain: Option<String>,
    pub port: Option<u32>,
    pub path: Option<Vec<String>>,
    pub query: Option<String>,
    pub anchor: Option<String>,
}

Fieldsยง

ยงscheme: Option<String>ยงuser_pass: (Option<String>, Option<String>)ยงsubdomain: Option<String>ยงdomain: Option<String>ยงtop_level_domain: Option<String>ยงport: Option<u32>ยงpath: Option<Vec<String>>ยงquery: Option<String>ยงanchor: Option<String>

Implementationsยง

Sourceยง

impl Url

Source

pub fn host_str(&self) -> Option<String>

Extract the representation of the host for this URL.

ยงExample
use url_parse::core::Parser;
use url_parse::core::global::Domain;
let input = "https://user:pass@www.example.com:443/blog/article/search?docid=720&hl=en#dayone";
let expected = "example.com";
let parsed = Parser::new(None).parse(input).unwrap();
let result = parsed.host_str().unwrap();
assert_eq!(result, expected);
Source

pub fn port_or_known_default(&self) -> Option<u32>

Extract the username from the url.

ยงExample
use url_parse::core::Parser;
use url_parse::core::global::Domain;
let input = "https://user:pass@www.example.com:443/blog/article/search?docid=720&hl=en#dayone";
let expected = 443;
let parsed = Parser::new(None).parse(input).unwrap();
let result = parsed.port_or_known_default().unwrap();
assert_eq!(result, expected);
Source

pub fn username(&self) -> Option<String>

Extract the username from the url.

ยงExample
use url_parse::core::Parser;
use url_parse::core::global::Domain;
let input = "https://user:pass@www.example.com:443/blog/article/search?docid=720&hl=en#dayone";
let expected = "user";
let parsed = Parser::new(None).parse(input).unwrap();
let result = parsed.username().unwrap();
assert_eq!(result, expected);
Source

pub fn password(&self) -> Option<String>

Extract the password from the url.

ยงExample
use url_parse::core::Parser;
use url_parse::core::global::Domain;
let input = "https://user:pass@www.example.com:443/blog/article/search?docid=720&hl=en#dayone";
let expected = "pass";
let parsed = Parser::new(None).parse(input).unwrap();
let result = parsed.password().unwrap();
assert_eq!(result, expected);
Source

pub fn path_segments(&self) -> Option<Vec<String>>

Extract the path segments from the path.

ยงExample
use url_parse::core::Parser;
use url_parse::core::global::Domain;
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

pub fn serialize(&self) -> String

Serialize an URL struct to a String.

ยงExample
use url_parse::core::Parser;
use url_parse::core::global::Domain;
use url_parse::url::Url;

let input = 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".to_string()),
   anchor: Some("dayone".to_string()),
};
let expected =
   "https://user:pass@www.example.co.uk:443/blog/article/search?docid=720&hl=en#dayone";

let result = input.serialize();
assert_eq!(result, expected);
Source

pub fn empty() -> Self

Create a new empty instance with all fields set to none.

Trait Implementationsยง

Sourceยง

impl Debug for Url

Sourceยง

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

Formats the value using the given formatter. Read more
Sourceยง

impl Display for Url

Display the serialization of this URL.

Sourceยง

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

Formats the value using the given formatter. Read more
Sourceยง

impl PartialEq for Url

Compare two objects of this type.

Sourceยง

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 ยท Sourceยง

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

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> ToString for T
where T: Display + ?Sized,

Sourceยง

fn to_string(&self) -> String

Converts the given value to a String. 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.