Add basic support for async_std resolver
This commit is contained in:

committed by
Benjamin Fry

parent
06c406cfce
commit
5f8c39c243
@@ -25,12 +25,15 @@ use crate::error::*;
|
||||
use crate::lookup::{self, Lookup, LookupEither, LookupFuture};
|
||||
use crate::lookup_ip::{LookupIp, LookupIpFuture};
|
||||
use crate::lookup_state::CachingClient;
|
||||
#[cfg(feature = "async-std-runtime")]
|
||||
use crate::name_server::{AsyncStdConnection, AsyncStdConnectionProvider, AsyncStdRuntimeHandle};
|
||||
use crate::name_server::{
|
||||
ConnectionProvider, GenericConnection, GenericConnectionProvider, NameServerPool,
|
||||
RuntimeProvider,
|
||||
};
|
||||
#[cfg(feature = "tokio-runtime")]
|
||||
use crate::name_server::{TokioConnection, TokioConnectionProvider};
|
||||
|
||||
use crate::Hosts;
|
||||
|
||||
/// An asynchronous resolver for DNS generic over async Runtimes.
|
||||
@@ -67,6 +70,10 @@ pub struct AsyncResolver<C: DnsHandle, P: ConnectionProvider<Conn = C>> {
|
||||
hosts: Option<Arc<Hosts>>,
|
||||
}
|
||||
|
||||
/// An AsyncResolver used with async_std
|
||||
#[cfg(feature = "async-std-runtime")]
|
||||
pub type AsyncStdAsyncResolver = AsyncResolver<AsyncStdConnection, AsyncStdConnectionProvider>;
|
||||
|
||||
/// An AsyncResolver used with Tokio
|
||||
#[cfg(feature = "tokio-runtime")]
|
||||
pub type TokioAsyncResolver = AsyncResolver<TokioConnection, TokioConnectionProvider>;
|
||||
@@ -104,6 +111,38 @@ pub async fn $p(&self, query: $t) -> Result<$l, ResolveError> {
|
||||
};
|
||||
}
|
||||
|
||||
#[cfg(feature = "async-std-runtime")]
|
||||
impl AsyncStdAsyncResolver {
|
||||
/// Construct a new async-std based `AsyncResolver` with the provided configuration.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// * `config` - configuration, name_servers, etc. for the Resolver
|
||||
/// * `options` - basic lookup options for the resolver
|
||||
///
|
||||
/// # Returns
|
||||
///
|
||||
/// A tuple containing the new `AsyncResolver` and a future that drives the
|
||||
/// background task that runs resolutions for the `AsyncResolver`. See the
|
||||
/// documentation for `AsyncResolver` for more information on how to use
|
||||
/// the background future.
|
||||
pub async fn async_std(
|
||||
config: ResolverConfig,
|
||||
options: ResolverOpts,
|
||||
) -> Result<Self, ResolveError> {
|
||||
Self::new(config, options, AsyncStdRuntimeHandle).await
|
||||
}
|
||||
|
||||
/// Constructs a new async-std based Resolver with the system configuration.
|
||||
///
|
||||
/// This will use `/etc/resolv.conf` on Unix OSes and the registry on Windows.
|
||||
#[cfg(any(unix, target_os = "windows"))]
|
||||
#[cfg(feature = "system-config")]
|
||||
pub async fn async_std_from_system_conf() -> Result<Self, ResolveError> {
|
||||
Self::from_system_conf(AsyncStdRuntimeHandle).await
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "tokio-runtime")]
|
||||
impl TokioAsyncResolver {
|
||||
/// Construct a new Tokio based `AsyncResolver` with the provided configuration.
|
||||
|
Reference in New Issue
Block a user