url_parse/
lib.rs

1/*!
2
3A library for parsing URLs.
4
5 `url-parse` provides some missing schemes (`sftp`, `ssh`, `s3`) and enables the user to specify custom schemes before parsing.
6 # Example
7 ```rust,no_run
8 use url_parse::core::Parser;
9 use url_parse::url::Url;
10 let input = "https://user:pass@www.example.co.uk:443/blog/article/search?docid=720&hl=en#dayone";
11 let result = Parser::new(None).parse(input).unwrap();
12 assert_eq!(
13     result,
14     Url {
15         scheme: Some("https".to_string()),
16         user_pass: (Some("user".to_string()), Some("pass".to_string())),
17         subdomain: Some("www".to_string()),
18         domain: Some("example.co".to_string()),
19         top_level_domain: Some("uk".to_string()),
20         port: Some(443),
21         path: Some(vec![
22             "blog".to_string(),
23             "article".to_string(),
24             "search".to_string(),
25         ]),
26         query: Some("docid=720&hl=en#dayone".to_string()),
27         anchor: Some("dayone".to_string()),
28     }
29 )
30 ```
31
32 Passing a Some(HashMap) to Parser::new() can be used to create custom schemes.
33
34 The hashmap is a key,value pair representing the scheme name (key) to a port and description mapping (value).
35 # Example
36 ```rust,no_run
37 use std::collections::HashMap;
38 use url_parse::core::Parser;
39 use url_parse::url::Url;
40 let input = "myschema://user:pass@example.co.uk/path/to/file.txt";
41 let mut myport_mappings = HashMap::new();
42 myport_mappings.insert("myschema", (8888, "My custom schema"));
43 let result = Parser::new(Some(myport_mappings)).parse(input).unwrap();
44 assert_eq!(
45     result,
46     Url {
47         scheme: Some("myschema".to_string()),
48         user_pass: (Some("user".to_string()), Some("pass".to_string())),
49         subdomain: Some("www".to_string()),
50         domain: Some("example.co".to_string()),
51         top_level_domain: Some("uk".to_string()),
52         port: Some(8888),
53         path: Some(vec![
54             "path".to_string(),
55             "to".to_string(),
56             "file.txt".to_string(),
57         ]),
58         query: None,
59         anchor: None,
60     }
61 )
62 ```
63*/
64pub mod core;
65pub mod error;
66pub mod url;
67pub mod utils;