url-parse
A library for parsing URLs.
Why?
No current other crate with support for i.e. special schemes. The reasoning is that schemes need to be part of the whatwg standard to be supported.
url-parse
provides some missing schemes (sftp
, ssh
, s3
) and enables the user to specify custom schemes before parsing.
Usage
Basic
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:
let input = "https://user:pass@www.example.co.uk:443/blog/article/search?docid=720&hl=en#dayone";
let result = new.parse.unwrap;
assert_eq!
Custom schemes
Passing a Some(HashMap)
to Parser::new()
can be used to create custom schemes.
The hashmap is a key,value pair representing the scheme name (key) to a port and description mapping (value).
let input = "myschema://user:pass@example.co.uk/path/to/file.txt";
let mut myport_mappings = new;
myport_mappings.insert;
let result = new.parse.unwrap;
assert_eq!;