#uri #safe #url #http

safe_uri

简单且安全的 URI 类型

4 个版本

0.1.0-beta.42022 年 3 月 12 日
0.1.0-beta.32021 年 12 月 19 日
0.1.0-beta.22021 年 12 月 5 日

#49 in #uri

26 每月下载次数
用于 5 crates

MIT/Apache

115KB
3.5K SLoC

示例

使用和未使用 tapTap::tap_mut 构造 Uri 的所有部分。

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

依赖项