std.net.ip.IpAddress
class pub enum IpAddressAn IPv4 or IPv6 address.
Constructors
V4
V4(Ipv4Address)An IPv4 address.
V6
V6(Ipv6Address)An IPv6 address.
Static methods
parse
Show source codeHide source code
fn pub static parse(address: String) -> Option[IpAddress] {
if address.contains?(':') {
Ipv6Address.parse(address).map(fn (v) { V6(v) })
} else {
Ipv4Address.parse(address).map(fn (v) { V4(v) })
}
}fn pub static parse(address: String) -> Option[IpAddress]Parses an IPv4 or IPv6 address.
This method only supports IPv4 or IPv6 addresses. Port numbers, IPv6 zones, and CIDR masks are not supported.
Examples
Parsing an IPv4 address:
import std.net.ip (IpAddress)
IpAddress.parse('1.2.3.4') # => Option.Some(IpAddress.V4(Ipv4Address.new(1, 2, 3, 4)))
Parsing an IPv6 address:
import std.net.ip (IpAddress)
IpAddress.parse('::1') # => Option.Some(IpAddress.V6(Ipv6Address.new(0, 0, 0, 0, 0, 0, 0, 1)))
v4
Show source codeHide source code
fn pub static v4(a: Int, b: Int, c: Int, d: Int) -> IpAddress {
V4(Ipv4Address.new(a, b, c, d))
}fn pub static v4(a: Int, b: Int, c: Int, d: Int) -> IpAddressReturns a new IPv4 address.
This is a shortcut for IpAddress.V4(Ipv4Address.new(...)).
Examples
import std.net.ip (IpAddress)
IpAdress.v4(127, 0, 0, 1)
v6
Show source codeHide source code
fn pub static v6(
a: Int,
b: Int,
c: Int,
d: Int,
e: Int,
f: Int,
g: Int,
h: Int,
) -> IpAddress {
V6(Ipv6Address.new(a, b, c, d, e, f, g, h))
}fn pub static v6(a: Int, b: Int, c: Int, d: Int, e: Int, f: Int, g: Int, h: Int) -> IpAddressReturns a new IPv6 address.
This is a shortcut for IpAddress.V6(Ipv6Address.new(...)).
Examples
import std.net.ip (IpAddress)
IpAdress.v6(0, 0, 0, 0, 0, 0, 0, 1)
Instance methods
!=
Show source codeHide source code
fn pub !=(other: T) -> Bool {
(self == other).false?
}fn pub !=(other: T) -> BoolReturns true if self and the given object are not equal to each other.
==
Show source codeHide source code
fn pub ==(other: ref IpAddress) -> Bool {
match self {
case V4(a) -> {
match other {
case V4(b) -> a == b
case _ -> false
}
}
case V6(a) -> {
match other {
case V6(b) -> a == b
case _ -> false
}
}
}
}fn pub ==(other: ref IpAddress) -> BoolReturns true if self and the given object are equal to each other.
This operator is used to perform structural equality. This means two objects residing in different memory locations may be considered equal, provided their structure is equal. For example, two different arrays may be considered to have structural equality if they contain the exact same values.
clone
Show source codeHide source code
fn pub clone -> IpAddress {
match self {
case V4(ip) -> IpAddress.V4(ip.clone)
case V6(ip) -> IpAddress.V6(ip.clone)
}
}fn pub clone -> IpAddressCreates a clone of self.
documentation?
Show source codeHide source code
fn pub documentation? -> Bool {
match self {
case V4(ip) -> ip.documentation?
case V6(ip) -> ip.documentation?
}
}fn pub documentation? -> BoolReturns true if self is in the range designated for documentation.
fmt
Show source codeHide source code
fn pub fmt(formatter: mut Formatter) {
formatter.write(to_string)
}fn pub fmt(formatter: mut Formatter)Formats self in a human-readable format for debugging purposes.
into_string
Show source codeHide source code
fn pub move into_string -> String {
match self {
case V4(ip) -> ip.into_string
case V6(ip) -> ip.into_string
}
}fn pub move into_string -> StringMoves self into a String.
loopback?
Show source codeHide source code
fn pub loopback? -> Bool {
match self {
case V4(ip) -> ip.loopback?
case V6(ip) -> ip.loopback?
}
}fn pub loopback? -> BoolReturns true if self is a loopback address.
multicast?
Show source codeHide source code
fn pub multicast? -> Bool {
match self {
case V4(ip) -> ip.multicast?
case V6(ip) -> ip.multicast?
}
}fn pub multicast? -> BoolReturns true if self is a multicast address.
to_string
Show source codeHide source code
fn pub to_string -> String {
match self {
case V4(ip) -> ip.to_string
case V6(ip) -> ip.to_string
}
}fn pub to_string -> StringConverts self to a String.
unspecified?
Show source codeHide source code
fn pub unspecified? -> Bool {
match self {
case V4(ip) -> ip.unspecified?
case V6(ip) -> ip.unspecified?
}
}fn pub unspecified? -> BoolReturns true if self is the special "unspecified" address.
v4?
Show source codeHide source code
fn pub v4? -> Bool {
match self {
case V4(_) -> true
case _ -> false
}
}fn pub v4? -> BoolReturns true if self is an IPv4 address.
v6?
Show source codeHide source code
fn pub v6? -> Bool {
match self {
case V6(_) -> true
case _ -> false
}
}fn pub v6? -> BoolReturns true if self is an IPv6 address.
Implemented traits
Clone
impl Clone[IpAddress] for IpAddressEqual
impl Equal[ref IpAddress] for IpAddressFormat
impl Format for IpAddressIntoString
impl IntoString for IpAddressToString
impl ToString for IpAddress