use std::iter;
use std::net::{IpAddr, Ipv4Addr};
#[derive(PartialEq, Eq, Hash, Clone)]
pub struct Interface {
pub name: String,
pub index: Option<u32>
}
impl Default for Interface {
fn default() -> Self {
Self {
name: String::from("fallback-interface"),
index: Some(1),
}
}
}
impl Interface {
pub fn ip(&self) -> IpAddr {
Ipv4Addr::UNSPECIFIED.into()
}
}
pub struct InterfaceTracker<D> {
data: D,
interface: Interface,
}
impl<D: Default> InterfaceTracker<D> {
pub fn new() -> Self {
Self {
data: D::default(),
interface: Interface::default(),
}
}
pub fn iter_mut(&mut self) -> impl Iterator<Item=(&Interface, &mut D)> {
iter::once((&self.interface, &mut self.data))
}
pub fn iter_mapping(&self) -> impl Iterator<Item=(u32, Ipv4Addr)> {
iter::once((1, Ipv4Addr::UNSPECIFIED))
}
pub fn poll_updates(&mut self, mut on_new_ip: impl FnMut(Ipv4Addr)) {
}
}