Crates.io | url-lite |
lib.rs | url-lite |
version | 0.1.0 |
source | src |
created_at | 2023-02-11 10:09:04.745932 |
updated_at | 2023-02-11 10:09:04.745932 |
description | no_std URL parser |
homepage | https://github.com/johanholmerin/url-lite |
repository | https://github.com/johanholmerin/url-lite |
max_upload_size | |
id | 782431 |
size | 42,145 |
Port of the URL parser from nodejs/http-parser to Rust
#[no_std]
&str
cargo add url_lite
use url_lite::{Url, ParseError};
// Note that ParseError doesn't implement the Error trait unless the `unstable`
// feature is enabled
assert!(Url::parse("not-an-url") == Err(ParseError::Invalid))
let input = "https://usr:pass@example.com:8080/some%20path?foo=bar#zzz";
let url = Url::parse(input).expect("Invalid URL");
assert_eq!(url.schema, Some("https"));
assert_eq!(url.host, Some("example.com"));
assert_eq!(url.port, Some("8080"));
assert_eq!(url.path, Some("/some%20path"));
assert_eq!(url.query, Some("foo=bar"));
assert_eq!(url.fragment, Some("zzz"));
assert_eq!(url.userinfo, Some("usr:pass"));
unstable
- Implements
core::error::Error
for ParseError
. Requires nightly due to
error_in_coreAlthough this is a port of the URL parser from http-parser and it passes all the tests, it has not been used in production. It is also not a generic parser, may not support all URLs, only returns slices, and performs no decoding.
If you need a robust URL parser and are okay with std/alloc dependency, use servo/rust-url instead.