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
use std::net::IpAddr;
use std::sync::Arc;

use crate::api::api::PortType;

#[derive(Debug)]
pub struct AddressValue<V> {
    pub value: V,
    pub from_port: u16,
    pub to_port: u16,
}

pub trait AddressLookup: 'static + Send + Sync {
    type Value: 'static + Send + Sync;

    fn lookup(&self, ip: IpAddr, port: u16, proto: PortType) -> Option<AddressValue<Self::Value>>;
}

impl<T: AddressLookup> AddressLookup for Arc<T> {
    type Value = T::Value;

    fn lookup(&self, ip: IpAddr, port: u16, proto: PortType) -> Option<AddressValue<Self::Value>> {
        T::lookup(&*self, ip, port, proto)
    }
}