[GH-ISSUE #1079] AsyncResolver type inference problem #600

Open
opened 2026-03-15 23:23:02 +03:00 by kerem · 1 comment
Owner

Originally created by @kornelski on GitHub (Apr 24, 2020).
Original GitHub issue: https://github.com/hickory-dns/hickory-dns/issues/1079

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:

  • R doesn't mean anything. Rustc dug out some internal name that isn't related to anything I wrote. It's impossible to know what this refers to without looking it up.

  • The documentation mentions GenericConnectionProvider<R>, but GenericConnectionProvider is a private trait, so it is completely undocumented. I can't look up what R is supposed to be. I can't search for what types implement it. I can't name it the code.

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?

Originally created by @kornelski on GitHub (Apr 24, 2020). Original GitHub issue: https://github.com/hickory-dns/hickory-dns/issues/1079 Code like this: ```rust 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: * `R` doesn't mean anything. Rustc dug out some internal name that isn't related to anything I wrote. It's impossible to know what this refers to without looking it up. * The documentation mentions `GenericConnectionProvider<R>`, but `GenericConnectionProvider` is a private trait, so it is completely undocumented. I can't look up what `R` is supposed to be. I can't search for what types implement it. I can't name it the code. 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?
Author
Owner

@bluejekyll commented on GitHub (Apr 24, 2020):

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.

<!-- gh-comment-id:619259912 --> @bluejekyll commented on GitHub (Apr 24, 2020): 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.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/hickory-dns#600
No description provided.