ipnet 2.12.0

Provides types and useful methods for working with IPv4 and IPv6 network addresses, commonly called IP prefixes. The new `IpNet`, `Ipv4Net`, and `Ipv6Net` types build on the existing `IpAddr`, `Ipv4Addr`, and `Ipv6Addr` types already provided in Rust's standard library and align to their design to stay consistent. The module also provides useful traits that extend `Ipv4Addr` and `Ipv6Addr` with methods for `Add`, `Sub`, `BitAnd`, and `BitOr` operations. The module only uses stable feature so it is guaranteed to compile using the stable toolchain.
Documentation
use crate::IpNet;
use crate::Ipv4Net;
use crate::Ipv6Net;

#[cfg(not(feature = "std"))]
use alloc::borrow::Cow;
#[cfg(feature = "std")]
use std::borrow::Cow;

use schemars1::{json_schema, JsonSchema, Schema, SchemaGenerator};

impl JsonSchema for Ipv4Net {
    fn schema_name() -> Cow<'static, str> {
        "Ipv4Net".into()
    }

    fn json_schema(_: &mut SchemaGenerator) -> Schema {
        json_schema!({
            "title": "IPv4 network",
            "description": "An IPv4 address with prefix length",
            "examples": [
                "0.0.0.0/0",
                "192.168.0.0/24"
            ],
            "type": "string",
            "maxLength": 18,
            "pattern": r#"^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/(?:3[0-2]|[1-2][0-9]|[0-9])$"#
        })
    }
}
impl JsonSchema for Ipv6Net {
    fn schema_name() -> Cow<'static, str> {
        "Ipv6Net".into()
    }

    fn json_schema(_: &mut SchemaGenerator) -> Schema {
        json_schema!({
            "title": "IPv6 network",
            "description": "An IPv6 address with prefix length",
            "examples": [
                "::/0",
                "fd00::/32"
            ],
            "type": "string",
            "maxLength": 43,
            "pattern": r#"^[0-9A-Fa-f:\.]+\/(?:[0-9]|[1-9][0-9]|1[0-1][0-9]|12[0-8])$"#
        })
    }
}
impl JsonSchema for IpNet {
    fn schema_name() -> Cow<'static, str> {
        "IpNet".into()
    }

    fn json_schema(gen: &mut SchemaGenerator) -> Schema {
        json_schema!({
            "title": "IP network",
            "description": "An IPv4 or IPv6 address with prefix length",
            "examples": [
                "192.168.0.0/24",
                "fd00::/32"
            ],
            "oneOf": [
                gen.subschema_for::<Ipv4Net>(),
                gen.subschema_for::<Ipv6Net>()
            ]
        })
    }
}