Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
addrezz
Generic, RFC-compliant address parsing with confident defaults.
addrezz parses anything that names a network endpoint (URLs, bare domains,
IP literals, IPv6, SSH/SCP-style remotes) into one normalized [Addr] type.
It fills in sensible defaults (scheme for bare hosts, IANA default ports) and
exposes the parts you actually reach for: scheme, host, port, userinfo, path,
query, and fragment.
[]
= "0.1"
Optional integrations are behind feature flags (see Feature flags).
Basic usage
One entry point, many input shapes:
use ;
// Full URL.
let a = parse.unwrap;
assert_eq!;
assert_eq!;
assert_eq!;
// Bare host: the scheme is filled in (https by default).
let a = parse.unwrap;
assert_eq!;
// SCP-style git remote becomes ssh.
let a = parse.unwrap;
assert_eq!;
assert_eq!;
// IP literals, v4 and v6.
let a = parse.unwrap;
assert!;
let a = parse.unwrap;
assert!;
Ports and schemes carry their IANA semantics:
use Addr;
let a = parse.unwrap;
assert_eq!; // none was written
assert_eq!; // scheme default
let a = parse.unwrap;
assert!;
Pull apart the path and query without re-parsing:
use Addr;
let a = parse.unwrap;
let segs: = a.path_segments.collect;
assert_eq!; // percent-decoded
let pairs: = a.query_pairs.collect;
assert_eq!;
Compare origins (RFC 6454) and spot local addresses:
use Addr;
let a = parse.unwrap;
let b = parse.unwrap;
assert!; // default port is implied
let a = parse.unwrap;
assert!;
Build values at compile time or run time with the macros:
use ;
let a = addr!; // runtime parse, panics on bad input
let b = addrezz!; // compile-time, errors at the call site
See docs/MACROS.md for the full set (addr!, try_addr!,
addrezz!, addrezz_vec!).
serde
Every public type derives Serialize / Deserialize behind the serde
feature. Addr serializes as a struct, so the components stay addressable in
the serialized form.
= { = "0.1", = ["serde"] }
use Addr;
let a = parse.unwrap;
let json = to_string_pretty.unwrap;
// {
// "scheme": "Https",
// "userinfo": { "username": "user", "password": "secret" },
// "host": { "Domain": "api.example.com" },
// "port": 8443,
// "path": "/v1",
// "query": "q=1",
// "fragment": null
// }
let back: Addr = from_str.unwrap;
assert_eq!;
If you want Addr stored as a single string instead of a struct, serialize
its Display form (a.to_string()) and Addr::parse it back.
url
With the url feature, Addr converts to and from [url::Url]. Conversions
are fallible because url::Url is stricter about some shapes.
= { = "0.1", = ["url"] }
use Addr;
use Url;
let a = parse.unwrap;
let u: Url = a.clone.try_into.unwrap;
assert_eq!;
let back: Addr = .try_into.unwrap;
assert_eq!;
http
The http feature converts Addr into the http crate's types: Uri,
Authority, and a Host-header HeaderValue. Useful when building requests
by hand.
= { = "0.1", = ["http"] }
use Addr;
use ;
let a = parse.unwrap;
let uri: Uri = .try_into.unwrap;
let auth: Authority = .try_into.unwrap; // user@example.com:8443
// Ready for the `Host` request header. The port is elided when it
// matches the scheme default, kept otherwise.
let host: HeaderValue = .try_into.unwrap;
assert_eq!;
reqwest
The reqwest feature adds conversions to reqwest::Url (and implies http).
Because reqwest::Url re-exports url::Url, enabling url already covers
these conversions; the separate feature is for crates that depend on reqwest
without naming url directly.
= { = "0.1", = ["reqwest"] }
use Addr;
let a = parse.unwrap;
// Hand the URL straight to a reqwest client.
let url: Url = a.try_into.unwrap;
let resp = new.get.send.await?;
# Ok::
sqlx
With the sqlx feature, Addr implements Type / Encode / Decode,
stored as TEXT / VARCHAR. Decoding runs the stored string back through
Addr::parse. Works on any sqlx backend with a String type (Postgres,
MySQL, SQLite).
= { = "0.1", = ["sqlx"] }
use Addr;
# async
Feature flags
| Feature | Default | What it adds |
|---|---|---|
default_http |
bare hosts default to http (mutually exclusive with above) |
|
macros |
yes | the compile-time addrezz! / addrezz_vec! proc macros |
redact |
yes | Debug for Userinfo hides the password (docs) |
serde |
Serialize / Deserialize on all public types |
|
url |
conversions to/from url::Url |
|
http |
conversions to http::Uri, Authority, HeaderValue |
|
reqwest |
conversions to reqwest::Url (implies http) |
|
resolve |
blocking DNS via getaddrinfo (docs) |
|
resolve_async |
async DNS via hickory-resolver (docs) |
|
whois |
whois lookups via whoizz (docs) |
|
psl |
public suffix / eTLD+1 via psl (docs) |
|
ipnet |
CIDR membership tests via ipnet (docs) |
|
arbitrary |
arbitrary::Arbitrary for fuzzing (docs) |
|
proptest |
proptest::Arbitrary strategy (docs) |
The crate ships default = ["macros", "redact"]. Disable
defaults with default-features = false if you want http as the bare-host
scheme or a leaner build.
More integrations
The widely used ones are above. The rest each have a short page with a runnable example:
- docs/MACROS.md —
addr!,try_addr!,addrezz!,addrezz_vec! - docs/RESOLVE.md — DNS resolution, sync and async
- docs/WHOIS.md — registry/RIR whois lookups
- docs/PSL.md — public suffix, registered domain, subdomain
- docs/IPNET.md — CIDR / subnet membership
- docs/REDACT.md — keeping passwords out of logs
- docs/PROPTEST.md — property-testing with
Addr - docs/ARBITRARY.md — fuzzing with
Addr
License
Licensed under either of MIT or Apache-2.0 at your option.