Rust insert into HashMap 给出错误方法 `insert` exists for struct `HashMap<f64, i64>`, but its trait bounds were not satisfied

问题描述 投票:0回答:0

我在尝试插入 Rust 中的 HashMap 时遇到错误。

use std::collections::HashMap;

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

错误:

 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

游乐场

有什么建议吗?

rust hashmap
© www.soinside.com 2019 - 2024. All rights reserved.