【发布时间】:2021-09-27 18:22:15
【问题描述】:
我有一个很奇怪的问题:当我用 HashMap::new() 创建一个 HashMap 时,一切正常,但是当我用 HashMap::capacity_and_hasher 创建一个 hashmap 时,我不能使用插入方法
错误:
|
93 | map.insert(1,2);
| ^^^^^^ method cannot be called on `HashMap<_, _, &RandomState>` due to unsatisfied trait bounds
|
= note: the following trait bounds were not satisfied:
`&RandomState: BuildHasher`
代码:
let s = RandomState::new();
let mut map = HashMap::with_hasher(&s);
map.insert(1,2);
【问题讨论】: