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
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 Freeze for Url
impl RefUnwindSafe for Url
impl Send for Url
impl Sync for Url
impl Unpin for Url
impl UnwindSafe for Url
Blanket Implementationsยง
Sourceยงimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Sourceยงfn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more