I'm checking my code through cargo clippy. it shows a warning below:
warning: usage of `contains_key` followed by `insert` on a `HashMap`
|
39 | / if !orderbooks.contains_key(&inst) {
40 | | orderbooks.insert(inst, T::new_update(update));
41 | | return Ok(());
42 | | }
| |_________^ consider using `orderbooks.entry(inst)`
|
= note: `#[warn(clippy::map_entry)]` on by default
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#map_entry
warning: 1 warning emitted
Finished dev [unoptimized + debuginfo] target(s) in 23.72s
As you can see, I need the function to return if i choose to add an entry. chaining entry
with or_insert
s in this case seems cant help much. Is there anyway more idiomatic?