Expand description
§address
This library aids in processing network addresses. It adds the domain, endpoint, host, & authority
types that std lacks. The types have strict validation, owned & borrowed variants, and standard
library conversions.
§Usage
address = "0.23.0"§Features
This crate has no dependencies by default. The following optional features add dependencies:
idna: AddsDomain::parse_unicode&to_unicodefor international domain names.serde: Adds theSerialize&Deserializeimplementations for all address types.
§Address Types
There are 6 core address types:
| Host | Without a port | With a port |
|---|---|---|
| IP Address | IPAddress | SocketAddress |
| Domain | Domain & DomainRef | Endpoint & EndpointRef |
| (Either) | Host & HostRef | Authority & AuthorityRef |
Types that are not inherently Copy come in owned & reference pairs; the IP & socket address types
are Copy, so they have no reference form. The Ref types borrow their text, so they can parse &
convert without allocation.
§Example
use address::{Authority, SocketAddress};
// Parsing validates and normalizes the address types.
let authority: Authority = "Example.com:443".parse().unwrap();
assert_eq!(authority.to_string(), "example.com:443");
assert_eq!(authority.port(), 443);
// You can easily convert between address types.
let authority: Authority = "127.0.0.1:80".parse().unwrap();
let socket: SocketAddress = authority.to_socket().unwrap();
assert_eq!(socket.to_string(), "127.0.0.1:80");
// You can even convert to the addresses provided in the standard library.
use std::net::SocketAddr;
let socket: SocketAddr = socket.to_std();
assert_eq!(socket, "127.0.0.1:80".parse().unwrap());Structs§
- Authority
- A Host with an associated port.
- Authority
Ref - An Authority reference.
- Domain
- A domain name.
- Domain
Ref - A Domain reference.
- Endpoint
- A Domain with an associated port.
- Endpoint
Ref - An Endpoint reference.
- IPv4
Address - An IPv4 address. (a.b.c.d)
- IPv6
Address - An IPv6 address. (a:b:c:d:e:f:g:h)
- Invalid
Address Error - An error parsing an address that preserves the owned
value. - Labels
- An iterator over the labels of a domain name.
- Socket
Address - An IPAddress with an associated port.
- Socket
Address V4 - An IPv4Address with an associated port.
- Socket
Address V6 - An IPv6Address with an associated port.
Enums§
- Host
- Either a Domain or an IPAddress.
- HostRef
- A Host reference.
- IPAddress
- Either an IPv4Address or an IPv6Address.
- Parse
Error - An error parsing an address.