1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
use core::borrow::Borrow;
use core::cmp::Ord;
use core::fmt::Debug;
use core::hash::Hash;

#[cfg(feature = "std")]
use super::PrefixSet;
use super::{
    primitive, Address, Bitmask, Hostmask, Interface, Netmask, Prefix, PrefixLength, PrefixRange,
};
use crate::{any, concrete, fmt};

/// An interface for describing an IP address family.
pub trait Afi: Copy + Debug + Hash + Ord + 'static {
    // This bound is required to satisfy coherence rules when implementing
    // `From<A::Octets> for Address<A>`
    /// The big-endian byte array representation of addresses of this address
    /// family.
    type Octets: Borrow<[u8]>;

    /// The primitive integer type used to store address values of this address
    /// family.
    type Primitive: primitive::Address<Self> + fmt::AddressDisplay<Self>;

    /// Get the [`concrete::Afi`] variant associated with `Self`.
    fn as_afi() -> concrete::Afi;
}

/// Provides an interface for describing a class of IP address families.
pub trait AfiClass: Copy + Debug + Hash + Ord {
    /// The type representing IP address values of this address family class.
    type Address: Address;

    /// The type representing IP netmask values of this address family class.
    type Netmask: Netmask;

    /// The type representing IP hostmask values of this address family class.
    type Hostmask: Hostmask;

    /// The type representing bitmask values of this address family class.
    type Bitmask: Bitmask;

    /// The type representing IP prefix-length values of this address family
    /// class.
    type PrefixLength: PrefixLength + Into<Self::Netmask> + Into<Self::Hostmask>;

    /// The type representing IP prefix values of this address family class.
    type Prefix: Prefix<Address = Self::Address, Length = Self::PrefixLength, Netmask = Self::Netmask>
        + Into<Self::PrefixRange>;

    /// The type representing IP interface values of this address family class.
    type Interface: Interface<
        Address = Self::Address,
        Prefix = Self::Prefix,
        PrefixLength = Self::PrefixLength,
    >;

    /// The type representing IP prefix range values of this address family
    /// class.
    type PrefixRange: PrefixRange<Prefix = Self::Prefix, Length = Self::PrefixLength>;

    /// The type representing IP prefix-sets of this address family class.
    #[cfg(feature = "std")]
    type PrefixSet: for<'a> PrefixSet<'a, Prefix = Self::Prefix, Range = Self::PrefixRange>;

    /// Get the [`any::AfiClass`] variant associated with `Self`.
    fn as_afi_class() -> any::AfiClass;
}