I'm trying to use fuzzy select in my project.
Below is the Cargo.toml
file.
[package]
name = "dialoguer-examples"
version = "0.1.0"
edition = "2021"
[[bin]]
name = "fuzzyselect"
path = "src/main.rs"
[dependencies]
dialoguer = "0.11.0"
Below in my main.rs
program -
use dialoguer::FuzzySelect;
fn main() {
let items = vec!["foo", "bar", "baz"];
let selection = FuzzySelect::new()
.with_prompt("What do you choose?")
.items(&items)
.interact()
.unwrap();
println!("You chose: {}", items[selection]);
}
When I run this program I get below error -
cargo run
Compiling fuzzyselect-examples v0.1.0 (/Users/user/Documents/Coding/others/fuzzyselect-examples)
error[E0432]: unresolved import `dialoguer::FuzzySelect`
--> src/main.rs:1:5
|
1 | use dialoguer::FuzzySelect;
| ^^^^^^^^^^^^^^^^^^^^^^ no `FuzzySelect` in the root
|
note: found an item that was configured out
--> /Users/user/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/dialoguer-0.11.0/src/lib.rs:47:32
|
47 | pub use prompts::fuzzy_select::FuzzySelect;
| ^^^^^^^^^^^
note: the item is gated behind the `fuzzy-select` feature
--> /Users/user/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/dialoguer-0.11.0/src/lib.rs:46:7
|
46 | #[cfg(feature = "fuzzy-select")]
| ^^^^^^^^^^^^^^^^^^^^^^^^
For more information about this error, try `rustc --explain E0432`.
error: could not compile `fuzzyselect-examples` (bin "fuzzyselect-examples") due to 1 previous error
I tried to use password example, it is working fine. Only Fuzzy select has the problem.
I tried to use prompts::fuzzy_select::FuzzySelect
but it didn't work.
How can I fix this error?
I tried running the code in my local, the issue is you are missing features in Cargo.toml
.
dialoguer = { version = "0.11.0", features = ["fuzzy-select"] }
Complete Code:
Cargo.toml
file
[package]
name = "fuzzySelect"
version = "0.1.0"
edition = "2024"
[dependencies]
dialoguer = { version = "0.11.0", features = ["fuzzy-select"] }
main.rs
file:
use dialoguer::FuzzySelect;
fn main() {
let items = vec!["apple", "banana", "grape", "orange", "watermelon"];
let selection = FuzzySelect::new()
.with_prompt("Pick your favorite fruit")
.items(&items)
.interact()
.unwrap();
println!("You selected: {}", items[selection]);
}
I have created a complete running example on github.