jonhoo / flurry

A port of Java's ConcurrentHashMap to Rust

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Tedious map constructors

jonhoo opened this issue · comments

Since HashMap's various constructors are now generic over S where S: Default, you now often have to explicitly write something like:

let map: HashMap<_, _> = HashMap::new();

This is strictly more generic (it'll work with any S), but it's also kind of annoying. One option is to basically undo 17d138f and have those methods just be implemented for the DefaultHashBuilder instead. That would make the above (and much other code) not have to repeat the type. Thoughts?

In the standard HashMap, new and with_capacity are only defined with the default S.
https://doc.rust-lang.org/std/collections/struct.HashMap.html#method.new

Otherwise, you have to use the constructors with an actual instance: with_hasher and with_capacity_and_hasher. The only time S: Default is required and used is for Default and FromIterator.

Fixed by #52.