#parser #uri

oni-comb-uri-rs

A Rust crate for uri parser

39 releases

new 0.2.30 Mar 25, 2023
0.2.5 Feb 28, 2023
0.2.4 Oct 14, 2022
0.0.4 Mar 2, 2022
0.0.3 Nov 15, 2021

#268 in Parser implementations

Download history 5/week @ 2022-12-02 14/week @ 2022-12-09 1/week @ 2022-12-23 1/week @ 2023-01-06 8/week @ 2023-01-13 7/week @ 2023-01-20 9/week @ 2023-01-27 14/week @ 2023-02-03 35/week @ 2023-02-10 26/week @ 2023-02-17 53/week @ 2023-02-24 129/week @ 2023-03-03 133/week @ 2023-03-10 133/week @ 2023-03-17

448 downloads per month

MIT/Apache

240KB
6K SLoC

oni-comb-uri-rs

A Rust crate for URI.

Specification

This crate is based on the following specifications.

  • RFC3986: Uniform Resource Identifier (URI): Generic Syntax

Usage

use oni_comb_uri::uri::Uri;

let s = "http://user1:pass1@localhost:8080/example?key1=value1&key2=value2&key1=value2#f1";

match Uri::parse(s) {
  Ok(uri) => {
    uri.schema().into_iter().for_each(|s| assert_eq!(s.to_string(), "http"));
    uri
      .host_name()
      .into_iter()
      .for_each(|hn| assert_eq!(hn.to_string(), "localhost"));
    uri.port().into_iter().for_each(|p| assert_eq!(p, 8080));
    uri.user_info().into_iter().for_each(|ui| {
      assert_eq!(ui.user_name(), "user1");
      assert_eq!(ui.password(), Some("pass1"));
    });
    uri
      .path()
      .into_iter()
      .for_each(|p| assert_eq!(p.to_string(), "/example"));
    uri.query().into_iter().for_each(|q| {
      q.get_param("key1".to_string()).into_iter().for_each(|v| {
        assert_eq!(v.len(), 2);
        assert_eq!(v[0], "value1");
        assert_eq!(v[1], "value2");
      });
      q.get_param("key2".to_string()).into_iter().for_each(|v| {
        assert_eq!(v.len(), 1);
        assert_eq!(v[0], "value2");
      });
    });
    uri.fragment().into_iter().for_each(|f| assert_eq!(f, "f1"));
    println!("{:?}", uri);
  }
  Err(e) => println!("{:?}", e),
}

Dependencies

~1–1.4MB
~39K SLoC