ip/traits/
af.rs

1use core::fmt::Debug;
2use core::hash::Hash;
3
4#[cfg(feature = "std")]
5use super::PrefixSet;
6use super::{
7    primitive, Address, Bitmask, Hostmask, Interface, Netmask, Prefix, PrefixLength, PrefixRange,
8};
9use crate::{any, concrete, fmt};
10
11/// An interface for describing an IP address family.
12pub trait Afi: Copy + Debug + Hash + Ord + 'static {
13    // This bound is required to satisfy coherence rules when implementing
14    // `From<A::Octets> for Address<A>`
15    /// The big-endian byte array representation of addresses of this address
16    /// family.
17    type Octets: primitive::Octets;
18
19    /// The primitive integer type used to store address values of this address
20    /// family.
21    type Primitive: primitive::Address<Self> + fmt::AddressDisplay<Self>;
22
23    /// Get the [`concrete::Afi`] variant associated with `Self`.
24    fn as_afi() -> concrete::Afi;
25}
26
27/// Provides an interface for describing a class of IP address families.
28pub trait AfiClass: Copy + Debug + Hash + Ord {
29    /// The type representing IP address values of this address family class.
30    type Address: Address;
31
32    /// The type representing IP netmask values of this address family class.
33    type Netmask: Netmask;
34
35    /// The type representing IP hostmask values of this address family class.
36    type Hostmask: Hostmask;
37
38    /// The type representing bitmask values of this address family class.
39    type Bitmask: Bitmask;
40
41    /// The type representing IP prefix-length values of this address family
42    /// class.
43    type PrefixLength: PrefixLength + Into<Self::Netmask> + Into<Self::Hostmask>;
44
45    /// The type representing IP prefix values of this address family class.
46    type Prefix: Prefix<Address = Self::Address, Length = Self::PrefixLength, Netmask = Self::Netmask>
47        + Into<Self::PrefixRange>;
48
49    /// The type representing IP interface values of this address family class.
50    type Interface: Interface<
51        Address = Self::Address,
52        Prefix = Self::Prefix,
53        PrefixLength = Self::PrefixLength,
54    >;
55
56    /// The type representing IP prefix range values of this address family
57    /// class.
58    type PrefixRange: PrefixRange<Prefix = Self::Prefix, Length = Self::PrefixLength>;
59
60    /// The type representing IP prefix-sets of this address family class.
61    #[cfg(feature = "std")]
62    type PrefixSet: for<'a> PrefixSet<'a, Prefix = Self::Prefix, Range = Self::PrefixRange>;
63
64    /// Get the [`any::AfiClass`] variant associated with `Self`.
65    fn as_afi_class() -> any::AfiClass;
66}