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
sourceimpl Url
impl Url
sourcepub fn host_str(&self) -> Option<String>
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);
sourcepub fn port_or_known_default(&self) -> Option<u32>
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);
sourcepub fn username(&self) -> Option<String>
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);
sourcepub fn password(&self) -> Option<String>
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);
sourcepub fn path_segments(&self) -> Option<Vec<String>>
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);
sourcepub fn serialize(&self) -> String
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);
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for Url
impl Send for Url
impl Sync for Url
impl Unpin for Url
impl UnwindSafe for Url
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more