ipnet
IpNet, Ipv4Net, and Ipv6Net types for working with IP network addresses (CIDR) in Rust.
Repository Health
Technical Analysis
ipnet provides IpNet, Ipv4Net, and Ipv6Net types for representing and manipulating IP network addresses (CIDR prefixes) in Rust, built directly on top of the standard library’s IpAddr, Ipv4Addr, and Ipv6Addr types to stay API-consistent with them. It adds subnet and address-range iterators (Ipv4Subnets, Ipv6Subnets, Ipv4AddrRange, Ipv6AddrRange) plus extension traits giving Add/Sub/BitAnd/BitOr arithmetic on IP addresses that the standard library omits.
The crate only uses stable Rust features, targets no_std environments via an optional std feature, and supports optional serde serialization (with a heapless variant to avoid dynamic allocation) and schemars JSON Schema generation — making it a common low-level building block for networking, firewall, and infrastructure tooling written in Rust.
What You Get
IpNet,Ipv4Net, andIpv6Nettypes for representing CIDR network prefixes, parseable from strings ("10.1.1.0/24".parse()) and usable inconstcontextsIpv4Subnets/Ipv6Subnetsiterators for enumerating subnets within an address range, andIpv4AddrRange/Ipv6AddrRangefor iterating individual addresses- Extension traits adding
Add,Sub,BitAnd, andBitOroperations toIpv4Addr/Ipv6Addr, which the standard library doesn’t provide - Optional
serde(withheaplessno-alloc variant) andschemars(JSON Schema, v0.8 or v1) integration behind feature flags
Common Use Cases
- Parsing and validating CIDR blocks in network configuration, firewall rules, or infrastructure-as-code tooling written in Rust
- Enumerating all subnets or hosts within an IP range for allocation, scanning, or reporting tools
- Serializing/deserializing network address ranges to/from JSON or config formats via the optional serde feature
- Embedded or
no_stdnetworking code that needs CIDR arithmetic without pulling in the full standard library
Under The Hood
Architecture — the crate splits cleanly by concern: src/ipnet.rs (2,001 lines) defines the core IpNet/Ipv4Net/Ipv6Net types and their subnet/range iterator logic; src/parser.rs handles CIDR string parsing; src/mask.rs implements netmask/hostmask bit manipulation; src/ipext.rs (989 lines) adds the Add/Sub/BitAnd/BitOr extension traits onto std::net::Ipv4Addr/Ipv6Addr; and src/ipnet_serde.rs/ipnet_schemars_08.rs/ipnet_schemars_1.rs are optional, feature-gated integration shims kept isolated from the core so the zero-dependency default build stays lean. Tech Stack — pure Rust, 2018 edition, using only stable-toolchain features (no nightly-only APIs), with optional dependencies on serde (derive), schemars (v0.8 or v1, mutually exclusive), and heapless for allocation-free serialization; a std feature flag (on by default) gates the parts requiring the standard library, keeping a no_std path viable. Code Quality — the README states tests aim for thorough coverage across both dedicated test modules and doctests embedded in the public API’s documentation; the code is stable and mature (297 total commits, MSRV frozen at Rust 1.26+ since the 2.0 rewrite that replaced a custom 128-bit integer emulation with native u128 support). API Design — types deliberately mirror the standard library’s IpAddr/Ipv4Addr/Ipv6Addr naming and construction patterns (new(), from_str(), TryFrom), including const-compatible constructors (new_assert) added for compile-time network definitions, so Rust developers already familiar with std::net face almost no additional learning curve.
Used by 3 apps in this directory
fabro
Developer Tools · Devops
Define AI agent workflows as code graphs, route tasks across any LLM, and intervene only where it matters.
OpenShell
AI Agents · Developer Tools
The safe, private runtime that lets autonomous AI agents operate in sandboxed environments governed by declarative YAML policies — blocking data exfiltration, credential leaks, and unauthorized network activity before they happen.
Svix
Developer Tools · Automation
Open source, self-hostable webhook infrastructure that handles delivery, retries, HMAC signing, and multi-tenant event management so you never have to build a webhooks system from scratch.