4 releases

0.1.0-beta.4 Mar 12, 2022
0.1.0-beta.3 Dec 19, 2021
0.1.0-beta.2 Dec 5, 2021

#49 in #uri

26 downloads per month
Used in 5 crates

MIT/Apache

115KB
3.5K SLoC

Examples

Constructing all parts of a Uri with and without tap and Tap::tap_mut.

use safe_uri::*;
use tap::Tap;

let uri_with_tap = Uri::new().tap_mut(|u| {
u.scheme = Scheme::try_from("https").unwrap();
u.authority = Some(Authority::new().tap_mut(|a| {
a.user_info = Some(UserInfo::try_from("alice").unwrap());
a.host = Host::Name(HostName::try_from("example.com").unwrap());
a.port = Some(443);
}));
u.resource = Resource::new().tap_mut(|r| {
r.path = Path::try_from("/hello").unwrap();
r.query = Some(Query::try_from("country=NL&city=Amsterdam").unwrap());
r.fragment = Some(Fragment::try_from("greeting").unwrap());
})
});

let mut authority = Authority::new();
authority.user_info = Some(UserInfo::try_from("alice").unwrap());
authority.host = Host::Name(HostName::try_from("example.com").unwrap());
authority.port = Some(443);
let mut resource = Resource::new();
resource.path = Path::try_from("/hello").unwrap();
resource.query = Some(Query::try_from("country=NL&city=Amsterdam").unwrap());
resource.fragment = Some(Fragment::try_from("greeting").unwrap());
let mut uri = Uri::new();
uri.scheme = Scheme::try_from("https").unwrap();
uri.authority = Some(authority);
uri.resource = resource;

assert_eq!(uri_with_tap, uri);

Dependencies