cidr/
lib.rs

1#![cfg_attr(doc_cfg, feature(doc_cfg))]
2#![cfg_attr(not(feature = "std"), no_std)]
3#![cfg_attr(feature = "no_unsafe", forbid(unsafe_code))]
4#![warn(missing_docs)]
5#![warn(rust_2018_idioms)]
6#![doc(html_root_url = "https://docs.rs/cidr/0.2.3")]
7#![allow(clippy::match_like_matches_macro)]
8
9//! This library provides types to represent an IP network ([`Cidr`]) or
10//! an IP host withing a network ([`Inet`])
11//!
12//! The naming follows the names of the [PostgreSQL data types](https://www.postgresql.org/docs/current/static/datatype-net-types.html)
13//!
14//! Address parsing also accepts IPv4 address with less than four octets
15//! (but always parses those as decimal); this is deprecated and will be
16//! removed in 0.3.0.
17//!
18//! If the `#` flag is used with the `Display` formatting (i.e. `{:#}`) the
19//! prefix will be shown even for host addresses (added in `0.1.1`).
20//!
21//! # Feature `no_unsafe`
22//!
23//! Enables `#![forbid(unsafe_code)]` for the whole crate; needs to use
24//! some workarounds that are likely slower than their `unsafe` variants.
25//!
26//! # Feature `std`
27//!
28//! Enabled by default, also mandatory right now because [`std::net`] isn't
29//! available in [`core`].
30//!
31//! # Feature `serde`
32//!
33//! This feature enables various types to be serialized using `serde`
34//! (without `serde-derive`).
35//!
36//! In human readable formats the `Display` and `FromStr` interfaces are
37//! used.  Otherwise all values are serialized in the same format (apart
38//! from the newtype wrapping) as a tuple of two values:
39//!
40//! - `tag: u8`:
41//!   - `0x00...0x20`: IPv4 with network length `tag`
42//!   - `0x40...0xc0`: IPv6 with network length `tag - 0x40`
43//!   - `0xff`: `any`
44//! - address according to `tag`: [`Ipv4Addr`] (`[u8; 4]`), [`Ipv6Addr`]
45//!   (`[u8; 16]`) or `()`
46//!
47//! The represenation hasn't been changed in 0.2; it is compatible with 0.1.
48//!
49//! # Feature `bitstring`
50//!
51//! This feature allows various types to be used as [`bitstring::BitString`],
52//! which allows them being in used in containers like [bitstring-trees].
53//!
54//! [bitstring-trees]: https://crates.io/crates/bitstring-trees
55//!
56//! [`Ipv4Addr`]: std::net::Ipv4Addr
57//! [`Ipv6Addr`]: std::net::Ipv6Addr
58
59pub use self::{
60	cidr::{
61		AnyIpCidr,
62		IpCidr,
63		Ipv4Cidr,
64		Ipv6Cidr,
65	},
66	family::Family,
67	inet::{
68		IpInet,
69		Ipv4Inet,
70		Ipv6Inet,
71	},
72	inet_iterator::{
73		InetAddressIterator,
74		InetIterator,
75	},
76	inet_pair::{
77		IpInetPair,
78		Ipv4InetPair,
79		Ipv6InetPair,
80	},
81	traits::{
82		Address,
83		Cidr,
84		Inet,
85		InetPair,
86	},
87};
88
89pub mod errors;
90pub mod parsers;
91
92mod serde_common;
93
94mod address;
95mod cidr;
96mod family;
97mod inet;
98mod inet_iterator;
99mod inet_pair;
100mod internal_traits;
101mod local_addr_parser;
102mod num;
103mod traits;