From c69e9cd81c8f5f922c3fdbe3af1aab40f73580aa Mon Sep 17 00:00:00 2001 From: parkma99 Date: Mon, 28 Oct 2024 21:19:45 +0800 Subject: [PATCH] add array impl --- rama-dns/src/lib.rs | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/rama-dns/src/lib.rs b/rama-dns/src/lib.rs index b9e00fe7..46918326 100644 --- a/rama-dns/src/lib.rs +++ b/rama-dns/src/lib.rs @@ -131,6 +131,36 @@ where } } +impl DnsResolver for [R; N] +where + R: DnsResolver + Send, + E: Send + 'static, +{ + type Error = DnsChainDomainResolveErr; + + async fn ipv4_lookup(&self, domain: Domain) -> Result, Self::Error> { + let mut errors = Vec::new(); + for resolver in self { + match resolver.ipv4_lookup(domain.clone()).await { + Ok(ipv4s) => return Ok(ipv4s), + Err(err) => errors.push(err), + } + } + Err(DnsChainDomainResolveErr { errors }) + } + + async fn ipv6_lookup(&self, domain: Domain) -> Result, Self::Error> { + let mut errors = Vec::new(); + for resolver in self { + match resolver.ipv6_lookup(domain.clone()).await { + Ok(ipv6s) => return Ok(ipv6s), + Err(err) => errors.push(err), + } + } + Err(DnsChainDomainResolveErr { errors }) + } +} + macro_rules! impl_dns_resolver_either_either { ($id:ident, $($param:ident),+ $(,)?) => { impl<$($param),+> DnsResolver for ::rama_core::combinators::$id<$($param),+>