Skip to main content

Crate address

Crate address 

Source
Expand description

§address

Build Crates.io Docs.rs License

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: Adds Domain::parse_unicode & to_unicode for international domain names.
  • serde: Adds the Serialize & Deserialize implementations for all address types.

§Address Types

There are 6 core address types:

HostWithout a portWith a port
IP AddressIPAddressSocketAddress
DomainDomain & DomainRefEndpoint & EndpointRef
(Either)Host & HostRefAuthority & 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.
AuthorityRef
An Authority reference.
Domain
A domain name.
DomainRef
A Domain reference.
Endpoint
A Domain with an associated port.
EndpointRef
An Endpoint reference.
IPv4Address
An IPv4 address. (a.b.c.d)
IPv6Address
An IPv6 address. (a:b:c:d:e:f:g:h)
InvalidAddressError
An error parsing an address that preserves the owned value.
Labels
An iterator over the labels of a domain name.
SocketAddress
An IPAddress with an associated port.
SocketAddressV4
An IPv4Address with an associated port.
SocketAddressV6
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.
ParseError
An error parsing an address.