pevensie/net
pevensie/net
contains convencience functions for working with
IP addresses and other networking-related tasks.
Types
An IP address. Can be either an IPv4 or IPv6 address. Data is stored
as a record of integers. To display an IP address, use the
format_ip_address
function.
pub type IpAddress {
IpV4(Int, Int, Int, Int)
IpV6(Int, Int, Int, Int, Int, Int, Int, Int)
}
Constructors
-
IpV4(Int, Int, Int, Int)
-
IpV6(Int, Int, Int, Int, Int, Int, Int, Int)
Functions
pub fn format_ip_address(ip: IpAddress) -> String
Formats an IP address as a string. This is useful for displaying IP addresses in a user-friendly way, or for inserting them into a database.
pub fn parse_ip_address(ip: String) -> Result(IpAddress, Nil)
Parses an IP address from a string. Returns an error if the string
is not a valid IP address. Accepts relaxed IPv4 and IPv6 formats,
such as 127.1
and 2001:db8::1
.