0

Why is the following program showing an error?

main.rs

use strum::IntoEnumIterator; // 0.17.1
use strum_macros::EnumIter; // 0.17.1

#[derive(Debug, EnumIter)]
enum Direction {
    NORTH,
    SOUTH,
    EAST,
    WEST,
}

fn main() {
    for direction in Direction::iter() {
        println!("{:?}", direction);
    }
}

Cargo.toml

[package]
name = "my-project"
version = "0.1.0"
authors = ["runner"]
edition = "2021"

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

[dependencies]
strum = "0.17.1"
strum_macros = "0.17.1"


Output

/nix/store/wr96avpynqcbwp90jwf65bvzq80qldan-cargo_run/bin/cargo_run
    Updating crates.io index
  Downloaded heck v0.3.3
  Downloaded unicode-segmentation v1.10.1
  Downloaded strum_macros v0.17.1
  Downloaded strum v0.17.1
  Downloaded 4 crates (123.1 KB) in 0.62s
   Compiling unicode-segmentation v1.10.1
   Compiling heck v0.3.3
   Compiling strum_macros v0.17.1
   Compiling strum v0.17.1
   Compiling my-project v0.1.0 (/home/runner/09-Iterate-thorugh-an-enum-in-Rust)
error: /nix/store/9bh3986bpragfjmr32gay8p95k91q4gy-glibc-2.33-47/lib/libpthread.so.0: undefined symbol: __libc_siglongjmp, version GLIBC_PRIVATE
 --> src/main.rs:2:5
  |
2 | use strum_macros::EnumIter; // 0.17.1
  |     ^^^^^^^^^^^^

error: cannot determine resolution for the derive macro `EnumIter`
 --> src/main.rs:4:17
  |
4 | #[derive(Debug, EnumIter)]
  |                 ^^^^^^^^
  |
  = note: import resolution is stuck, try simplifying macro imports

error[E0599]: no variant or associated item named `iter` found for enum `Direction` in the current scope
  --> src/main.rs:13:33
   |
5  | enum Direction {
   | -------------- variant or associated item `iter` not found for this enum
...
13 |     for direction in Direction::iter() {
   |                                 ^^^^ variant or associated item not found in `Direction`
   |
   = help: items from traits can only be used if the trait is implemented and in scope
   = note: the following trait defines an item `iter`, perhaps you need to implement it:
           candidate #1: `IntoEnumIterator`

warning: unused import: `strum::IntoEnumIterator`
 --> src/main.rs:1:5
  |
1 | use strum::IntoEnumIterator; // 0.17.1
  |     ^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: `#[warn(unused_imports)]` on by default

For more information about this error, try `rustc --explain E0599`.
warning: `my-project` (bin "my-project") generated 1 warning
error: could not compile `my-project` due to 3 previous errors; 1 warning emitted
exit status 101
 
user366312
  • 16,949
  • 65
  • 235
  • 452

0 Answers0