[GH-ISSUE #1004] Can't create custom ResolverOpts #589

Closed
opened 2026-03-15 23:19:35 +03:00 by kerem · 4 comments
Owner

Originally created by @ackintosh on GitHub (Jan 31, 2020).
Original GitHub issue: https://github.com/hickory-dns/hickory-dns/issues/1004

I would like to create custom ResolverOpts which has ip_strategy: LookupIpStrategy::Ipv6Only in order to query AAAA record but I got the compile error:

    let resolver = Resolver::new(
        ResolverConfig::default(),
        ResolverOpts {
            ndots: 1,
            timeout: Duration::from_secs(5),
            attempts: 2,
            rotate: false,
            check_names: true,
            edns0: false,
            validate: false,
            ip_strategy: LookupIpStrategy::Ipv6Only,
            cache_size: 32,
            use_hosts_file: true,
            positive_min_ttl: None,
            negative_min_ttl: None,
            positive_max_ttl: None,
            negative_max_ttl: None,
            distrust_nx_responses: true,
            num_concurrent_reqs: 2,
        }
    ).unwrap();
    let resolver = Resolver::new(
        ResolverConfig::default(),
        ResolverOpts {
            ip_strategy: LookupIpStrategy::Ipv6Only,
            ..ResolverOpts::default()
        }
    ).unwrap();
error[E0451]: field `rotate` of struct `trust_dns_resolver::config::ResolverOpts` is private
  --> src/main.rs:14:13
   |
14 |             rotate: false,
   |             ^^^^^^^^^^^^^ field `rotate` is private

error[E0451]: field `check_names` of struct `trust_dns_resolver::config::ResolverOpts` is private
  --> src/main.rs:15:13
   |
15 |             check_names: true,
   |             ^^^^^^^^^^^^^^^^^ field `check_names` is private

error[E0451]: field `edns0` of struct `trust_dns_resolver::config::ResolverOpts` is private
  --> src/main.rs:16:13
   |
16 |             edns0: false,
   |             ^^^^^^^^^^^^ field `edns0` is private

error: aborting due to 3 previous errors

(trust-dns-resolver 0.19.2)


Is there any way to create custom ResolverOpts?

Originally created by @ackintosh on GitHub (Jan 31, 2020). Original GitHub issue: https://github.com/hickory-dns/hickory-dns/issues/1004 I would like to create custom [ResolverOpts](https://github.com/bluejekyll/trust-dns/blob/master/crates/resolver/src/config.rs#L634) which has `ip_strategy: LookupIpStrategy::Ipv6Only` in order to query AAAA record but I got the compile error: ```rust let resolver = Resolver::new( ResolverConfig::default(), ResolverOpts { ndots: 1, timeout: Duration::from_secs(5), attempts: 2, rotate: false, check_names: true, edns0: false, validate: false, ip_strategy: LookupIpStrategy::Ipv6Only, cache_size: 32, use_hosts_file: true, positive_min_ttl: None, negative_min_ttl: None, positive_max_ttl: None, negative_max_ttl: None, distrust_nx_responses: true, num_concurrent_reqs: 2, } ).unwrap(); ``` ```rust let resolver = Resolver::new( ResolverConfig::default(), ResolverOpts { ip_strategy: LookupIpStrategy::Ipv6Only, ..ResolverOpts::default() } ).unwrap(); ``` ``` error[E0451]: field `rotate` of struct `trust_dns_resolver::config::ResolverOpts` is private --> src/main.rs:14:13 | 14 | rotate: false, | ^^^^^^^^^^^^^ field `rotate` is private error[E0451]: field `check_names` of struct `trust_dns_resolver::config::ResolverOpts` is private --> src/main.rs:15:13 | 15 | check_names: true, | ^^^^^^^^^^^^^^^^^ field `check_names` is private error[E0451]: field `edns0` of struct `trust_dns_resolver::config::ResolverOpts` is private --> src/main.rs:16:13 | 16 | edns0: false, | ^^^^^^^^^^^^ field `edns0` is private error: aborting due to 3 previous errors ``` (trust-dns-resolver 0.19.2) --- Is there any way to create custom ResolverOpts?
Author
Owner

@bluejekyll commented on GitHub (Jan 31, 2020):

This second construction of the Opts should work for you, is it not?:

       ResolverOpts {
            ip_strategy: LookupIpStrategy::Ipv6Only,
            ..ResolverOpts::default()
        }

Specify all the fields you want before the ..ResolverOpts::default()

<!-- gh-comment-id:580827697 --> @bluejekyll commented on GitHub (Jan 31, 2020): This second construction of the Opts should work for you, is it not?: ``` ResolverOpts { ip_strategy: LookupIpStrategy::Ipv6Only, ..ResolverOpts::default() } ``` Specify all the fields you want before the `..ResolverOpts::default()`
Author
Owner

@ackintosh commented on GitHub (Jan 31, 2020):

Hmm... I got the same error with the second construction:

error[E0451]: field `rotate` of struct `trust_dns_resolver::config::ResolverOpts` is private
  --> src/main.rs:37:15
   |
37 |             ..ResolverOpts::default()
   |               ^^^^^^^^^^^^^^^^^^^^^^^ field `rotate` is private

error[E0451]: field `check_names` of struct `trust_dns_resolver::config::ResolverOpts` is private
  --> src/main.rs:37:15
   |
37 |             ..ResolverOpts::default()
   |               ^^^^^^^^^^^^^^^^^^^^^^^ field `check_names` is private

error[E0451]: field `edns0` of struct `trust_dns_resolver::config::ResolverOpts` is private
  --> src/main.rs:37:15
   |
37 |             ..ResolverOpts::default()
   |               ^^^^^^^^^^^^^^^^^^^^^^^ field `edns0` is private

error: aborting due to 3 previous errors

Is it due to pub(crate) visibility?

github.com/bluejekyll/trust-dns@2724575aaf/crates/resolver/src/config.rs (L644-L650)

<!-- gh-comment-id:580848444 --> @ackintosh commented on GitHub (Jan 31, 2020): Hmm... I got the same error with the second construction: ``` error[E0451]: field `rotate` of struct `trust_dns_resolver::config::ResolverOpts` is private --> src/main.rs:37:15 | 37 | ..ResolverOpts::default() | ^^^^^^^^^^^^^^^^^^^^^^^ field `rotate` is private error[E0451]: field `check_names` of struct `trust_dns_resolver::config::ResolverOpts` is private --> src/main.rs:37:15 | 37 | ..ResolverOpts::default() | ^^^^^^^^^^^^^^^^^^^^^^^ field `check_names` is private error[E0451]: field `edns0` of struct `trust_dns_resolver::config::ResolverOpts` is private --> src/main.rs:37:15 | 37 | ..ResolverOpts::default() | ^^^^^^^^^^^^^^^^^^^^^^^ field `edns0` is private error: aborting due to 3 previous errors ``` Is it due to `pub(crate)` visibility? https://github.com/bluejekyll/trust-dns/blob/2724575aaf4d63cc9e79f0ec18546554d3221a13/crates/resolver/src/config.rs#L644-L650
Author
Owner

@bluejekyll commented on GitHub (Feb 1, 2020):

Huh, well we can make those public to make this easier. I think the motivation here was to not make options public that might create awkward issues. If you want to submit a PR for this, that would be great. As a work around, you can do this:

let mut opts = ResolverOpts::default();
opts.ip_strategy = LookupIpStrategy::Ipv6Only;

That should work without issue.

<!-- gh-comment-id:581035378 --> @bluejekyll commented on GitHub (Feb 1, 2020): Huh, well we can make those public to make this easier. I think the motivation here was to not make options public that might create awkward issues. If you want to submit a PR for this, that would be great. As a work around, you can do this: ```rust let mut opts = ResolverOpts::default(); opts.ip_strategy = LookupIpStrategy::Ipv6Only; ``` That should work without issue.
Author
Owner

@ackintosh commented on GitHub (Feb 2, 2020):

I've confirmed that workaround works. Thanks!

I'll file a PR for this. :octocat:

<!-- gh-comment-id:581090510 --> @ackintosh commented on GitHub (Feb 2, 2020): I've confirmed that workaround works. Thanks! I'll file a PR for this. :octocat:
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#589
No description provided.