mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
replace #[async_trait] with native async trait for trait Resolver (#6751)
This commit is contained in:
@ -1,20 +1,17 @@
|
||||
//! Perform DNS lookups
|
||||
|
||||
use async_trait::async_trait;
|
||||
use parking_lot::RwLock;
|
||||
use std::collections::HashMap;
|
||||
use std::{collections::HashMap, future::Future};
|
||||
use tracing::trace;
|
||||
pub use trust_dns_resolver::{error::ResolveError, TokioAsyncResolver};
|
||||
use trust_dns_resolver::{name_server::ConnectionProvider, AsyncResolver};
|
||||
|
||||
/// A type that can lookup DNS entries
|
||||
#[async_trait]
|
||||
pub trait Resolver: Send + Sync + Unpin + 'static {
|
||||
/// Performs a textual lookup and returns the first text
|
||||
async fn lookup_txt(&self, query: &str) -> Option<String>;
|
||||
fn lookup_txt(&self, query: &str) -> impl Future<Output = Option<String>> + Send;
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl<P: ConnectionProvider> Resolver for AsyncResolver<P> {
|
||||
async fn lookup_txt(&self, query: &str) -> Option<String> {
|
||||
// See: [AsyncResolver::txt_lookup]
|
||||
@ -67,7 +64,6 @@ impl DnsResolver {
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl Resolver for DnsResolver {
|
||||
async fn lookup_txt(&self, query: &str) -> Option<String> {
|
||||
Resolver::lookup_txt(&self.0, query).await
|
||||
@ -98,7 +94,6 @@ impl MapResolver {
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl Resolver for MapResolver {
|
||||
async fn lookup_txt(&self, query: &str) -> Option<String> {
|
||||
self.get(query)
|
||||
@ -110,7 +105,6 @@ impl Resolver for MapResolver {
|
||||
pub(crate) struct TimeoutResolver(pub(crate) std::time::Duration);
|
||||
|
||||
#[cfg(test)]
|
||||
#[async_trait]
|
||||
impl Resolver for TimeoutResolver {
|
||||
async fn lookup_txt(&self, _query: &str) -> Option<String> {
|
||||
tokio::time::sleep(self.0).await;
|
||||
|
||||
Reference in New Issue
Block a user