Make collections::VecMap generic over its key type#19715
Make collections::VecMap generic over its key type#19715tbu- wants to merge 1 commit intorust-lang:masterfrom
collections::VecMap generic over its key type#19715Conversation
In order to accomplish this, a new trait `UintKey` is introduced that allows converting arbitrary types to `uint` indices and back. As this adds a new type parameter to `VecMap`, this is a [breaking-change]. To fix it, either annotate one of your insertions or set the key type to `uint` in a different way. This also fixes the previously broken `PartialEq` and `Eq` implementation of `VecMap`.
|
Can you provide a motivation for this? CC @aturon |
|
The motivation for this is that I can use my own, newtyped struct as a index, in a way similar to other collections providing a map functionality. |
|
|
|
Honestly this will probably have to go through some sort of RFC. If we're interested in this sort of pattern we could use it with Bitv and Trie as well. |
|
This is an interesting idea, and would bring the API into closer alignment with other maps. I'd want to default the type parameter to Using defaults would make this a largely backwards-compatible change, except that the key parameter wants to come before the value parameter... I do agree with @gankro -- as the libraries are stabilizing, changes like this increasingly need to go through the RFC process. Would you mind raising some discussion on this point on this RFC? We could probably add it in if there's broad support. |
|
Superseded by #20150. |
In order to accomplish this, a new trait
UintKeyis introduced that allowsconverting arbitrary types to
uintindices and back.As this adds a new type parameter to
VecMap, this is a [breaking-change]. Tofix it, either annotate one of your insertions or set the key type to
uintina different way.
This also fixes the previously broken
PartialEqandEqimplementation ofVecMap.