use std::{ net::{Ipv4Addr, Ipv6Addr}, sync::Arc, }; use async_trait::async_trait; use trust_dns_resolver::{ name_server::{GenericConnection, GenericConnectionProvider, TokioRuntime}, AsyncResolver, }; pub type Resolver = AsyncResolver>; pub type Resolvers = Vec>; #[async_trait] pub trait Lookup { async fn lookup_a(&self, record: String) -> Vec; async fn lookup_aaaa(&self, record: String) -> Vec; async fn lookup_ptr(&self, record: String) -> Vec; } #[async_trait] impl Lookup for Resolver { async fn lookup_a(&self, record: String) -> Vec { self.ipv4_lookup(record) .await .unwrap() .as_lookup() .record_iter() .map(|r| r.data().unwrap().clone().into_a().unwrap()) .collect() } async fn lookup_aaaa(&self, record: String) -> Vec { self.ipv6_lookup(record) .await .unwrap() .as_lookup() .record_iter() .map(|r| r.data().unwrap().clone().into_aaaa().unwrap()) .collect() } async fn lookup_ptr(&self, record: String) -> Vec { self.reverse_lookup(record.parse().unwrap()) .await .unwrap() .as_lookup() .record_iter() .map(|r| r.data().unwrap().clone().into_ptr().unwrap().to_string()) .collect() } }