48 lines
11 KiB
HTML
48 lines
11 KiB
HTML
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="Types for IPv4 and IPv6 network addresses."><title>ipnet - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Italic-81dc35de.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-MediumItalic-ccf7e434.woff2,FiraSans-Medium-e1aa3f0a.woff2,SourceCodePro-Regular-8badfe75.ttf.woff2,SourceCodePro-Semibold-aa29a496.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2"href="../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../static.files/rustdoc-ca0dd0c4.css"><meta name="rustdoc-vars" data-root-path="../" data-static-root-path="../static.files/" data-current-crate="ipnet" data-themes="" data-resource-suffix="" data-rustdoc-version="1.93.1 (01f6ddf75 2026-02-11) (Arch Linux rust 1:1.93.1-1)" data-channel="1.93.1" data-search-js="search-9e2438ea.js" data-stringdex-js="stringdex-a3946164.js" data-settings-js="settings-c38705f0.js" ><script src="../static.files/storage-e2aeef58.js"></script><script defer src="../crates.js"></script><script defer src="../static.files/main-a410ff4d.js"></script><noscript><link rel="stylesheet" href="../static.files/noscript-263c88ec.css"></noscript><link rel="alternate icon" type="image/png" href="../static.files/favicon-32x32-eab170b8.png"><link rel="icon" type="image/svg+xml" href="../static.files/favicon-044be391.svg"></head><body class="rustdoc mod crate"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><rustdoc-topbar><h2><a href="#">Crate ipnet</a></h2></rustdoc-topbar><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../ipnet/index.html">ipnet</a><span class="version">2.11.0</span></h2></div><div class="sidebar-elems"><ul class="block"><li><a id="all-types" href="all.html">All Items</a></li></ul><section id="rustdoc-toc"><h3><a href="#">Sections</a></h3><ul class="block top-toc"><li><a href="#organization" title="Organization">Organization</a></li><li><a href="#serde-support" title="Serde support">Serde support</a></li></ul><h3><a href="#structs">Crate Items</a></h3><ul class="block"><li><a href="#structs" title="Structs">Structs</a></li><li><a href="#enums" title="Enums">Enums</a></li><li><a href="#traits" title="Traits">Traits</a></li><li><a href="#functions" title="Functions">Functions</a></li></ul></section><div id="rustdoc-modnav"></div></div></nav><div class="sidebar-resizer" title="Drag to resize sidebar"></div><main><div class="width-limiter"><section id="main-content" class="content"><div class="main-heading"><h1>Crate <span>ipnet</span> <button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"><a class="src" href="../src/ipnet/lib.rs.html#1-106">Source</a> </span></div><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Types for IPv4 and IPv6 network addresses.</p>
|
||
<p>This module provides types and useful methods for working with IPv4
|
||
and IPv6 network addresses, commonly called IP prefixes. The new
|
||
<a href="enum.IpNet.html"><code>IpNet</code></a>, <a href="struct.Ipv4Net.html"><code>Ipv4Net</code></a>, and <a href="struct.Ipv6Net.html"><code>Ipv6Net</code></a> types build on the existing
|
||
<a href="https://doc.rust-lang.org/std/net/enum.IpAddr.html"><code>IpAddr</code></a>, <a href="https://doc.rust-lang.org/std/net/struct.Ipv4Addr.html"><code>Ipv4Addr</code></a>, and <a href="https://doc.rust-lang.org/std/net/struct.Ipv6Addr.html"><code>Ipv6Addr</code></a> types already provided in
|
||
Rust’s standard library and align to their design to stay
|
||
consistent.</p>
|
||
<p>The module also provides the <a href="enum.IpSubnets.html"><code>IpSubnets</code></a>, <a href="struct.Ipv4Subnets.html"><code>Ipv4Subnets</code></a>, and
|
||
<a href="struct.Ipv6Subnets.html"><code>Ipv6Subnets</code></a> types for iterating over the subnets contained in
|
||
an IP address range. The <a href="enum.IpAddrRange.html"><code>IpAddrRange</code></a>, <a href="struct.Ipv4AddrRange.html"><code>Ipv4AddrRange</code></a>, and
|
||
<a href="struct.Ipv6AddrRange.html"><code>Ipv6AddrRange</code></a> types for iterating over IP addresses in a range.
|
||
And traits that extend <code>Ipv4Addr</code> and <code>Ipv6Addr</code> with methods for
|
||
addition, subtraction, bitwise-and, and bitwise-or operations that
|
||
are missing in Rust’s standard library.</p>
|
||
<p>The module only uses stable features so it is guaranteed to compile
|
||
using the stable toolchain.</p>
|
||
<h2 id="organization"><a class="doc-anchor" href="#organization">§</a>Organization</h2>
|
||
<ul>
|
||
<li><a href="enum.IpNet.html"><code>IpNet</code></a> represents an IP network address, either IPv4 or IPv6.</li>
|
||
<li><a href="struct.Ipv4Net.html"><code>Ipv4Net</code></a> and <a href="struct.Ipv6Net.html"><code>Ipv6Net</code></a> are respectively IPv4 and IPv6 network
|
||
addresses.</li>
|
||
<li><a href="enum.IpSubnets.html"><code>IpSubnets</code></a>, <a href="struct.Ipv4Subnets.html"><code>Ipv4Subnets</code></a>, and <a href="struct.Ipv6Subnets.html"><code>Ipv6Subnets</code></a> are iterators
|
||
that generate the smallest set of IP network addresses bound by an
|
||
IP address range and minimum prefix length. These can be created
|
||
using their constructors. They are also returned by the
|
||
<a href="enum.IpNet.html#method.subnets"><code>subnets()</code></a> methods and used within the <a href="enum.IpNet.html#method.aggregate"><code>aggregate()</code></a> methods.</li>
|
||
<li><a href="enum.IpAddrRange.html"><code>IpAddrRange</code></a>, <a href="struct.Ipv4AddrRange.html"><code>Ipv4AddrRange</code></a>, and <a href="struct.Ipv6AddrRange.html"><code>Ipv6AddrRange</code></a> are
|
||
iterators that generate IP addresses. These can be created using
|
||
their constructors. They are also returned by the <a href="enum.IpNet.html#method.hosts"><code>hosts()</code></a>
|
||
methods.</li>
|
||
<li>The <a href="trait.IpAdd.html"><code>IpAdd</code></a>, <a href="trait.IpSub.html"><code>IpSub</code></a>, <a href="trait.IpBitAnd.html"><code>IpBitAnd</code></a>, <a href="trait.IpBitOr.html"><code>IpBitOr</code></a> traits extend
|
||
the <a href="https://doc.rust-lang.org/std/net/struct.Ipv4Addr.html"><code>Ipv4Addr</code></a> and <a href="https://doc.rust-lang.org/std/net/struct.Ipv6Addr.html"><code>Ipv6Addr</code></a> types with methods to perform
|
||
these operations.</li>
|
||
</ul>
|
||
<h2 id="serde-support"><a class="doc-anchor" href="#serde-support">§</a>Serde support</h2>
|
||
<p>This library comes with support for <a href="https://serde.rs">serde</a> but
|
||
it’s not enabled by default. Use the <code>serde</code> <a href="https://doc.rust-lang.org/cargo/reference/manifest.html#the-features-section">feature</a> to enable.</p>
|
||
<div class="example-wrap"><pre class="language-toml"><code>[dependencies]
|
||
ipnet = { version = "2", features = ["serde"] }</code></pre></div>
|
||
<p>For human readable formats (e.g. JSON) the <code>IpNet</code>, <code>Ipv4Net</code>, and
|
||
<code>Ipv6Net</code> types will serialize to their <code>Display</code> strings.</p>
|
||
<p>For compact binary formats (e.g. Bincode) the <code>Ipv4Net</code> and
|
||
<code>Ipv6Net</code> types will serialize to a string of 5 and 17 bytes that
|
||
consist of the network address octects followed by the prefix
|
||
length. The <code>IpNet</code> type will serialize to an Enum with the V4 or V6
|
||
variant index prepending the above string of 5 or 17 bytes.</p>
|
||
</div></details><h2 id="structs" class="section-header">Structs<a href="#structs" class="anchor">§</a></h2><dl class="item-table"><dt><a class="struct" href="struct.AddrParseError.html" title="struct ipnet::AddrParseError">Addr<wbr>Parse<wbr>Error</a></dt><dd>An error which can be returned when parsing an IP network address.</dd><dt><a class="struct" href="struct.Ipv4AddrRange.html" title="struct ipnet::Ipv4AddrRange">Ipv4<wbr>Addr<wbr>Range</a></dt><dd>An <code>Iterator</code> over a range of IPv4 addresses.</dd><dt><a class="struct" href="struct.Ipv4Net.html" title="struct ipnet::Ipv4Net">Ipv4Net</a></dt><dd>An IPv4 network address.</dd><dt><a class="struct" href="struct.Ipv4Subnets.html" title="struct ipnet::Ipv4Subnets">Ipv4<wbr>Subnets</a></dt><dd>An <code>Iterator</code> that generates IPv4 network addresses.</dd><dt><a class="struct" href="struct.Ipv6AddrRange.html" title="struct ipnet::Ipv6AddrRange">Ipv6<wbr>Addr<wbr>Range</a></dt><dd>An <code>Iterator</code> over a range of IPv6 addresses.</dd><dt><a class="struct" href="struct.Ipv6Net.html" title="struct ipnet::Ipv6Net">Ipv6Net</a></dt><dd>An IPv6 network address.</dd><dt><a class="struct" href="struct.Ipv6Subnets.html" title="struct ipnet::Ipv6Subnets">Ipv6<wbr>Subnets</a></dt><dd>An <code>Iterator</code> that generates IPv6 network addresses.</dd><dt><a class="struct" href="struct.PrefixLenError.html" title="struct ipnet::PrefixLenError">Prefix<wbr>LenError</a></dt><dd>An error which can be returned when the prefix length is invalid.</dd></dl><h2 id="enums" class="section-header">Enums<a href="#enums" class="anchor">§</a></h2><dl class="item-table"><dt><a class="enum" href="enum.IpAddrRange.html" title="enum ipnet::IpAddrRange">IpAddr<wbr>Range</a></dt><dd>An <code>Iterator</code> over a range of IP addresses, either IPv4 or IPv6.</dd><dt><a class="enum" href="enum.IpNet.html" title="enum ipnet::IpNet">IpNet</a></dt><dd>An IP network address, either IPv4 or IPv6.</dd><dt><a class="enum" href="enum.IpSubnets.html" title="enum ipnet::IpSubnets">IpSubnets</a></dt><dd>An <code>Iterator</code> that generates IP network addresses, either IPv4 or
|
||
IPv6.</dd></dl><h2 id="traits" class="section-header">Traits<a href="#traits" class="anchor">§</a></h2><dl class="item-table"><dt><a class="trait" href="trait.IpAdd.html" title="trait ipnet::IpAdd">IpAdd</a></dt><dd>Provides a <code>saturating_add()</code> method for <code>Ipv4Addr</code> and <code>Ipv6Addr</code>.</dd><dt><a class="trait" href="trait.IpBitAnd.html" title="trait ipnet::IpBitAnd">IpBit<wbr>And</a></dt><dd>Provides a <code>bitand()</code> method for <code>Ipv4Addr</code> and <code>Ipv6Addr</code>.</dd><dt><a class="trait" href="trait.IpBitOr.html" title="trait ipnet::IpBitOr">IpBitOr</a></dt><dd>Provides a <code>bitor()</code> method for <code>Ipv4Addr</code> and <code>Ipv6Addr</code>.</dd><dt><a class="trait" href="trait.IpSub.html" title="trait ipnet::IpSub">IpSub</a></dt><dd>Provides a <code>saturating_sub()</code> method for <code>Ipv4Addr</code> and <code>Ipv6Addr</code>.</dd></dl><h2 id="functions" class="section-header">Functions<a href="#functions" class="anchor">§</a></h2><dl class="item-table"><dt><a class="fn" href="fn.ip_mask_to_prefix.html" title="fn ipnet::ip_mask_to_prefix">ip_<wbr>mask_<wbr>to_<wbr>prefix</a></dt><dd>Converts a <code>IpAddr</code> network mask into a prefix.</dd><dt><a class="fn" href="fn.ipv4_mask_to_prefix.html" title="fn ipnet::ipv4_mask_to_prefix">ipv4_<wbr>mask_<wbr>to_<wbr>prefix</a></dt><dd>Converts a <code>Ipv4Addr</code> network mask into a prefix.</dd><dt><a class="fn" href="fn.ipv6_mask_to_prefix.html" title="fn ipnet::ipv6_mask_to_prefix">ipv6_<wbr>mask_<wbr>to_<wbr>prefix</a></dt><dd>Converts a <code>Ipv6Addr</code> network mask into a prefix.</dd></dl></section></div></main></body></html> |