hickory-dns / hickory-dns

A Rust based DNS client, server, and resolver
Other
4k stars 453 forks source link

AsyncResolver type inference problem #1079

Open kornelski opened 4 years ago

kornelski commented 4 years ago

Code like this:

let resolver = AsyncResolver::new(config, options, tokio::runtime::Handle::current().await?;
let lookup_result = resolver.srv_lookup(srv).await?;

fails to compile:

AsyncResolver::new(config, options, tokio::runtime::Handle::current()).await?;
^^^^^^^^^^^^^^^^^^ cannot infer type for type parameter `R`

This is problematic, because:

I had to read this crate's source code to discover that TokioConnectionProvider type alias exists and it happens to satisfy the mysterious R parameter. I'm surprised that the new function that takes a tokio handle is still generic over the runtime.

Could you add TokioConnectionProvider as the default type for this implementation, or make a less generic new_tokio function that automatically specifies this type?

bluejekyll commented 4 years ago

Ah, yes, we should clean this up. Probably deprecate the new? Some of these changes have come in as we've genericized the AsyncResolver across runtimes beyond Tokio into Fuchsia and AsyncStd. I've tried to document this as best as possible, but that can always be better. We should probably recommend to use the AsyncStdResolver, https://docs.rs/async-std-resolver/0.19.4/async_std_resolver/, or the TokioResolver, https://docs.rs/trust-dns-resolver/0.19.4/trust_dns_resolver/type.TokioAsyncResolver.html.

I'm happy to have suggestions for how we improve the experience here.