OxL Reference

data IpAddr

IPv4 or IPv6 address, kept in canonical text form (::0:1 is ::1).

Example:

oxl✓ checked in CI
use std.net { IpAddr }

fn main() io {
  match IpAddr.parse("::0:1") {
    IpAddr ip => print("{ip.toString()} v6={ip.isV6()} loopback={ip.isLoopback()}")
    ParseError e => print("bad: {e.msg}")
  }
}
Output
::1 v6=true loopback=true
@derive(Copy, Eq, Hash)
pub(api) data IpAddr

Thread safety. immutable; safe to share.

Since. 1.0.0-beta

Fields

pub(api) text: str

The address in canonical text form.

Methods

parse(text: str) -> IpAddr | ParseError
Parses numeric IPv4 / IPv6 text (names are not resolved
loopback() -> IpAddr
127.0.0.1, the IPv4 loopback address.
loopbackV6() -> IpAddr
::1, the IPv6 loopback address.
any() -> IpAddr
0.0.0.0: all IPv4 interfaces.
anyV6() -> IpAddr
::: all IPv6 interfaces (and IPv4 ones where the system maps them).
isV6() -> bool
Whether the address is IPv6.
isV4() -> bool
Whether the address is IPv4.
isLoopback() -> bool
Whether the address is ::1 or in 127.0.0.0/8.
toString() -> str
The canonical text of the address.

Defined in: std/net/net.oxl:105

See also