Function parse_url

Source
pub fn parse_url(url: &str) -> Result<UrlComponents, String>
Expand description

Convert given string into a UrlComponents struct

ยงExamples

use std::collections::HashMap;
use url_build_parse::{build_url, parse_url, UrlAuthority, UrlComponents, UrlUserInfo};

let authority = UrlAuthority {
    user_info: Option::from(
                    UrlUserInfo
                        {
                            username: "usr".to_string(),
                            password: Option::from("pwd".to_string())
                        }),
    host: "somehost".to_string(),
    port: Option::from(80)
};

let mut q = HashMap::new();
q.insert("q".to_string(), "123".to_string());


let url_components = UrlComponents {
    scheme: "https".to_string(),
    authority: Option::from(authority),
    path: "/".to_string(),
    query: Option::from(q),
    fragment: Option::from("fragment".to_string())
};

let url = build_url(url_components.clone()).unwrap();
assert_eq!("https://usr:pwd@somehost:80/?q=123#fragment", url.as_str());

let parsed_url_components = parse_url(url.as_str()).unwrap();
assert_eq!(url_components, parsed_url_components);