0

I am getting an error while trying to insert into a HashMap in Rust.

use std::collections::HashMap;

fn main() {
    let mut hm : HashMap<f64, i64> = HashMap::new();
    hm.insert(1.0, 10);
}

Error:

 Compiling playground v0.0.1 (/playground)
error[E0599]: the method `insert` exists for struct `HashMap<f64, i64>`, but its trait bounds were not satisfied
 --> src/main.rs:5:8
  |
5 |     hm.insert(1.0, 10);
  |        ^^^^^^
  |
  = note: the following trait bounds were not satisfied:
          `f64: Eq`
          `f64: Hash`

For more information about this error, try `rustc --explain E0599`.
error: could not compile `playground` due to previous error

Playground

Any suggestions?

Coder
  • 1,415
  • 2
  • 23
  • 49

0 Answers0