[GH-ISSUE #1652] Unable to customise ip_strategy #726

Closed
opened 2026-03-16 00:00:15 +03:00 by kerem · 6 comments
Owner

Originally created by @PurpleBooth on GitHub (Feb 28, 2022).
Original GitHub issue: https://github.com/hickory-dns/hickory-dns/issues/1652

Describe the bug

Currently there's no way to create a ResolverOpts to customize the IP Lookup Strategy due to it being flagged as non exhaustive.

To Reproduce
Steps to reproduce the behavior:

Try and create a struct to customise the IP Strategy, outside the crate.

ResolverOpts {
    ndots: 1,
    timeout: Duration::from_secs(5),
    attempts: 2,
    rotate: false,
    check_names: true,
    edns0: false,
    validate: false,
    ip_strategy,
    cache_size: 32,
    use_hosts_file: true,
    positive_min_ttl: None,
    negative_min_ttl: None,
    positive_max_ttl: None,
    negative_max_ttl: None,
    num_concurrent_reqs: 2,
    preserve_intermediates: false,
    try_tcp_on_error: true
}

Expected behavior
A clear and concise description of what you expected to happen.

To have a way to customize the Ip Strategy

Actual behavior

error[E0639]: cannot create non-exhaustive struct using struct expression
   --> src/main.rs:116:5
    |
116 | /     ResolverOpts {
117 | |         ndots: 1,
118 | |         timeout: Duration::from_secs(5),
119 | |         attempts: 2,
...   |
133 | |         try_tcp_on_error: true
134 | |     }
    | |_____^

The library to compile

System:

  • OS: macOS
  • Architecture: Intel Chipset (x86_64)
  • Version 12.2.1 (21D62)
  • rustc version: rustc 1.61.0-nightly (4b043faba 2022-02-24), rustc 1.59.0 (9d1b2106e 2022-02-23)

Version:
Crate: trust-dns-resolver
Version: v0.21.1

Additional context

This is currently fine with 0.20.4. This is an intended effect of non_exhaustive. I am not tied to constructing this way, I just need a way to cusomize the strategy.

Originally created by @PurpleBooth on GitHub (Feb 28, 2022). Original GitHub issue: https://github.com/hickory-dns/hickory-dns/issues/1652 **Describe the bug** Currently there's no way to create a `ResolverOpts` to customize the IP Lookup Strategy due to it being flagged as non exhaustive. **To Reproduce** Steps to reproduce the behavior: Try and create a struct to customise the IP Strategy, outside the crate. ```rust ResolverOpts { ndots: 1, timeout: Duration::from_secs(5), attempts: 2, rotate: false, check_names: true, edns0: false, validate: false, ip_strategy, cache_size: 32, use_hosts_file: true, positive_min_ttl: None, negative_min_ttl: None, positive_max_ttl: None, negative_max_ttl: None, num_concurrent_reqs: 2, preserve_intermediates: false, try_tcp_on_error: true } ``` **Expected behavior** A clear and concise description of what you expected to happen. To have a way to customize the Ip Strategy **Actual behavior** ``` error[E0639]: cannot create non-exhaustive struct using struct expression --> src/main.rs:116:5 | 116 | / ResolverOpts { 117 | | ndots: 1, 118 | | timeout: Duration::from_secs(5), 119 | | attempts: 2, ... | 133 | | try_tcp_on_error: true 134 | | } | |_____^ ``` The library to compile **System:** - OS: macOS - Architecture: Intel Chipset (x86_64) - Version 12.2.1 (21D62) - rustc version: rustc 1.61.0-nightly (4b043faba 2022-02-24), rustc 1.59.0 (9d1b2106e 2022-02-23) **Version:** Crate: trust-dns-resolver Version: v0.21.1 **Additional context** This is currently fine with 0.20.4. This is an intended effect of [non_exhaustive](https://github.com/rust-lang/rfcs/blob/master/text/2008-non-exhaustive.md). I am not tied to constructing this way, I just need a way to cusomize the strategy.
kerem closed this issue 2026-03-16 00:00:20 +03:00
Author
Owner

@djc commented on GitHub (Feb 28, 2022):

The way you do it is this:

let mut opts = ResolverOpts::default();
opts.ip_strategy = ..;
<!-- gh-comment-id:1054619898 --> @djc commented on GitHub (Feb 28, 2022): The way you do it is this: ```rust let mut opts = ResolverOpts::default(); opts.ip_strategy = ..; ```
Author
Owner

@PurpleBooth commented on GitHub (Feb 28, 2022):

Oh geez, worked. I am an idiot, thanks!

<!-- gh-comment-id:1054694933 --> @PurpleBooth commented on GitHub (Feb 28, 2022): Oh geez, worked. I am an idiot, thanks!
Author
Owner

@djc commented on GitHub (Feb 28, 2022):

No worries, I was only able to supply you with a quick response after taking about an hour to figure it out myself this morning! 😅

<!-- gh-comment-id:1054697545 --> @djc commented on GitHub (Feb 28, 2022): No worries, I was only able to supply you with a quick response after taking about an hour to figure it out myself this morning! 😅
Author
Owner

@bluejekyll commented on GitHub (Feb 28, 2022):

Maybe we should make all the fields hidden, and only use setter methods to remove this confusion. This isn’t the first time.

<!-- gh-comment-id:1054729559 --> @bluejekyll commented on GitHub (Feb 28, 2022): Maybe we should make all the fields hidden, and only use setter methods to remove this confusion. This isn’t the first time.
Author
Owner

@djc commented on GitHub (Mar 1, 2022):

Yeah, I think the builder pattern would be more idiomatic.

<!-- gh-comment-id:1055069610 --> @djc commented on GitHub (Mar 1, 2022): Yeah, I think the builder pattern would be more idiomatic.
Author
Owner

@PurpleBooth commented on GitHub (Mar 1, 2022):

I also spent a bit of time actually looking through the source expecting a builder pattern to be present

<!-- gh-comment-id:1055071537 --> @PurpleBooth commented on GitHub (Mar 1, 2022): I also spent a bit of time actually looking through the source expecting a builder pattern to be present
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#726
No description provided.