Skip to main content

Module ipaddr

Module ipaddr 

Source
Available on crate feature net only.
Expand description

IP address type for network programming.

This module provides a type-safe abstraction for IP addresses (IPv4 and IPv6), wrapping the standard library’s IpAddr type.

§Examples

use bare_types::net::IpAddr;
use core::net::{Ipv4Addr, Ipv6Addr};

// Create an IPv4 address
let v4 = IpAddr::new(core::net::IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)));
assert!(v4.is_ipv4());
assert!(v4.is_loopback());

// Create an IPv6 address
let v6 = IpAddr::new(core::net::IpAddr::V6(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1)));
assert!(v6.is_ipv6());
assert!(v6.is_loopback());

// Parse from string
let addr: IpAddr = "192.168.1.1".parse()?;

Structs§

IpAddr
An IP address (IPv4 or IPv6).

Enums§

IpAddrError
Error type for IP address parsing.