Skip to content

Instantly share code, notes, and snippets.

@barrybtw
Last active October 27, 2022 12:58
Show Gist options
  • Save barrybtw/03d4176d62e1ebe72e60eba746d233df to your computer and use it in GitHub Desktop.
Save barrybtw/03d4176d62e1ebe72e60eba746d233df to your computer and use it in GitHub Desktop.
C:\Code\rust-cli>cargo check
Checking rust-cli v0.1.0 (C:\Code\rust-cli)
error[E0277]: `Languages` doesn't implement `std::fmt::Display`
--> src\main.rs:30:16
|
30 | .items(&languages)
| ----- ^^^^^^^^^^ `Languages` cannot be formatted with the default formatter
| |
| required by a bound introduced by this call
|
= help: the trait `std::fmt::Display` is not implemented for `Languages`
= note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead
= note: required because of the requirements on the impl of `ToString` for `Languages`
note: required by a bound in `Select::<'_>::items`
--> C:\Users\Nicolai\.cargo\registry\src\github.com-1ecc6299db9ec823\dialoguer-0.10.2\src\prompts\select.rs:126:21
|
126 | pub fn items<T: ToString>(&mut self, items: &[T]) -> &mut Self {
| ^^^^^^^^ required by this bound in `Select::<'_>::items`
error[E0277]: `Languages` doesn't implement `std::fmt::Display`
--> src\main.rs:35:60
|
35 | Some(index) => println!("User selected item : {}", languages[index]),
| ^^^^^^^^^^^^^^^^ `Languages` cannot be formatted with the default formatter
|
= help: the trait `std::fmt::Display` is not implemented for `Languages`
= note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead
= note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)
For more information about this error, try `rustc --explain E0277`.
error: could not compile `rust-cli` due to 2 previous errors
use console::Term;
use dialoguer::{theme::ColorfulTheme, Select};
use strum::{EnumIter, IntoEnumIterator};
#[derive(Debug, EnumIter)]
enum Languages {
TypeScript,
JavaScript,
}
#[derive(Debug, EnumIter)]
enum PackageManagers {
Yarn,
Npm,
Pnpm,
}
#[derive(Debug, EnumIter)]
enum Packages {
Trpc,
Prisma,
Tailwind,
NextAuth,
}
// main function
fn main() -> std::io::Result<()> {
let languages: Vec<_> = Languages::iter().collect();
let selection = Select::with_theme(&ColorfulTheme::default())
.items(&languages)
.default(0)
.interact_on_opt(&Term::stderr())?;
match selection {
Some(index) => println!("User selected item : {}", languages[index]),
None => println!("User did not select anything"),
}
Ok(())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment