1 unstable release

0.1.0 Feb 11, 2023

#2207 in Parser implementations

Download history 17/week @ 2024-03-13 13/week @ 2024-03-20 16/week @ 2024-03-27 16/week @ 2024-04-03 3/week @ 2024-04-10 62/week @ 2024-04-17 43/week @ 2024-04-24 179/week @ 2024-05-01 70/week @ 2024-05-08 236/week @ 2024-05-15 142/week @ 2024-05-22 153/week @ 2024-05-29 183/week @ 2024-06-05 976/week @ 2024-06-12 692/week @ 2024-06-19 25/week @ 2024-06-26

1,936 downloads per month

MIT license

36KB
963 lines

url-lite

Port of the URL parser from nodejs/http-parser to Rust

Features

  • #[no_std]
  • No heap allocations, returns a struct of &str
  • Never panics(tested by dtolnay/no-panic)

Installation

cargo add url_lite

Example

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"));

Features

Caveats

Although 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.

Dependencies

~300–760KB
~18K SLoC