use core::fmt::{Debug, Display};
use core::hash::Hash;
use core::str::FromStr;
use super::{Address, Mask};
use crate::{concrete, error::Error};
mod len;
pub use self::len::Length;
mod range;
pub use self::range::Range;
mod set;
pub use self::set::Set;
pub trait Prefix:
Sized + Copy + Clone + Debug + Display + FromStr<Err = Error> + Hash + PartialEq + Eq + PartialOrd
{
type Address: Address;
type Length: Length;
type Hostmask: Mask;
type Netmask: Mask;
type Subprefixes: Iterator<Item = Self>;
fn network(&self) -> Self::Address;
fn hostmask(&self) -> Self::Hostmask;
fn netmask(&self) -> Self::Netmask;
fn max_prefix_len(&self) -> Self::Length;
fn prefix_len(&self) -> Self::Length;
fn broadcast(&self) -> Self::Address;
fn supernet(&self) -> Option<Self>;
fn is_sibling(&self, other: &Self) -> bool;
fn contains<T>(&self, other: &T) -> bool
where
Self: PartialOrd<T>,
{
self.ge(other)
}
fn subprefixes(&self, new_prefix_len: Self::Length) -> Result<Self::Subprefixes, Error>;
fn afi(&self) -> concrete::Afi {
self.network().afi()
}
fn new_prefix_length(&self, length: u8) -> Result<Self::Length, Error>;
}