Unresolved import in whois_rust crate

Hello everybody,

I'm an brand new rustacean, and I'm struggling with my first project.
As I'm trying to test out the crate whois_rust, I get this output from the compiler :

My code is very minimalistic and is just the example code form the crate's doc wrapped in a main function :

extern crate whois_rust;

use whois_rust::{WhoIs, WhoIsLookupOptions};

fn main() {
    let whois = WhoIs::from_path("/path/to/servers.json").unwrap();

    let result: String = whois.lookup(WhoIsLookupOptions::from_string("magiclen.org").unwrap()).unwrap();

    println!("{}", result);
}
[package]
name = "whoi_test"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
whois-rust = "1.4.0"

I don't know if I'm doing something wrong here ?

It looks like you've run into a bad combination of whois-rust having a technically-incomplete dependency specification and a breaking change in how rust resolves dependencies in the 2021 edition! This is unfortunate, and I'm sorry you ran into this in your first project.

This is a bug in whois-rust, but one which wouldn't have occurred until the new cargo feature resolver was activated by default in the 2021 edition. The edition mechanisms are usually very clean, and only apply to the current crate, but it looks like the default cargo features resolver applies to the whole dependency tree, I assume due to feature resolving happening at a global level.

The quick fix here is to add resolver = "1" right under edition = "2021" in your Cargo.toml. This will switch the Cargo feature resolver back to the original one, working around the bug in whois-rust. Once whois-rust fixes the issue, you can remove this line.

I've filed a bug in whois-rust for this issue. I believe this is technically an edition-breaking-change here, it has a simple backwards-compatible fix for whois-rust, and the fix does make their dependency specification technically more accurate.

6 Likes

Thank you so much. This works perfectly.

I was unsure if I needed to instead open an issue on the crate's github, but I'm glad I asked here, because it looks like this is a great community and I'm looking forward to participating in it ! :smile:

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.