Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace #[async_trait] with native async trait for trait Resolver #6751

Merged
merged 3 commits into from
Feb 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions crates/net/dns/src/resolver.rs
Original file line number Diff line number Diff line change
@@ -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]
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -98,7 +94,6 @@ impl MapResolver {
}
}

#[async_trait]
impl Resolver for MapResolver {
async fn lookup_txt(&self, query: &str) -> Option<String> {
self.get(query)
Expand All @@ -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;
Expand Down
Loading