pub struct Parser { /* private fields */ }
Implementations
sourceimpl Parser
impl Parser
sourcepub fn mixout_anchor<'a>(&self, input: &'a str) -> Option<&'a str>
pub fn mixout_anchor<'a>(&self, input: &'a str) -> Option<&'a str>
Extract the anchor from the url.
Example
use url_parse::url::Parser;
let input = "https://www.example.co.uk:443/blog/article/search?docid=720&hl=en#dayone";
let result = Parser::new(None).mixout_anchor(input).unwrap();
assert_eq!(result, "dayone");
sourceimpl Parser
impl Parser
sourcepub fn mixout_domain_fields<'a>(&self, input: &'a str) -> DomainFields<'a>
pub fn mixout_domain_fields<'a>(&self, input: &'a str) -> DomainFields<'a>
Extract the domain fields from the url.
Example
use url_parse::url::Parser;
use url_parse::url::global::DomainFields;
let input = "https://www.example.com:443/blog/article/search?docid=720&hl=en#dayone";
let expected = DomainFields {
subdomain: Some("www"),
domain: Some("example"),
top_level_domain: Some("com"),
};
let result = Parser::new(None).mixout_domain_fields(input);
assert_eq!(result, expected);
sourceimpl Parser
impl Parser
sourcepub fn mixout_login<'a>(
&self,
input: &'a str
) -> (Option<&'a str>, Option<&'a str>)
pub fn mixout_login<'a>(
&self,
input: &'a str
) -> (Option<&'a str>, Option<&'a str>)
Extract the domain fields from the url.
Example
use url_parse::url::Parser;
let input = "https://user:pass@www.example.co.uk";
let expected = (Some("user"), Some("pass"));
let result = Parser::new(None).mixout_login(input);
assert_eq!(result, expected);
sourceimpl Parser
impl Parser
sourcepub fn mixout_path<'a>(&self, input: &'a str) -> Option<Vec<&'a str>>
pub fn mixout_path<'a>(&self, input: &'a str) -> Option<Vec<&'a str>>
Extract the path as a vector from the url.
Example
use url_parse::url::Parser;
let input = "https://www.example.co.uk:443/blog/article/search?docid=720&hl=en#dayone";
let result = Parser::new(None).mixout_path(input).unwrap();
let expected = vec!["blog", "article", "search"];
assert_eq!(result, expected);
sourceimpl Parser
impl Parser
sourcepub fn mixout_port<'a>(&self, input: &'a str) -> Option<u32>
pub fn mixout_port<'a>(&self, input: &'a 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::url::Parser;
let input = "https://www.example.co.uk:443/blog/article/search?docid=720&hl=en#dayone";
let port = Parser::new(None).mixout_port(input);
assert_eq!(port.unwrap(), 443);
sourceimpl Parser
impl Parser
sourcepub fn mixout_query<'a>(&self, input: &'a str) -> Option<&'a str>
pub fn mixout_query<'a>(&self, input: &'a str) -> Option<&'a str>
Extract the query from the url.
Example
use url_parse::url::Parser;
let input = "https://www.example.co.uk:443/blog/article/search?docid=720&hl=en#dayone";
let result = Parser::new(None).mixout_query(input).unwrap();
assert_eq!(result, "docid=720&hl=en#dayone");
sourceimpl Parser
impl Parser
sourcepub fn mixout_scheme<'a>(&self, input: &'a str) -> Option<&'a str>
pub fn mixout_scheme<'a>(&self, input: &'a str) -> Option<&'a str>
Extract the query from the url.
Example
use url_parse::url::Parser;
let input = "https://www.example.co.uk:443/blog/article/search?docid=720&hl=en#dayone";
let scheme = Parser::new(None).mixout_scheme(input);
assert_eq!(scheme.unwrap(), "https");
sourceimpl Parser
impl Parser
sourcepub fn new(
port_mappings: Option<HashMap<&'static str, (u32, &'static str)>>
) -> Self
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::url::Parser;
let parser = Parser::new(None);
sourcepub fn parse(&self, url: &str) -> Result<Url, ParseError>
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::url::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
impl RefUnwindSafe for Parser
impl Send for Parser
impl Sync for Parser
impl Unpin for Parser
impl UnwindSafe for Parser
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
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