I have a HashMap<(String, usize), f64>
. I also have a &str
and a usize
, which I would like to look up in this HashMap
without cloning. Is there a way to lookup a (&str, usize)
as a (String, usize)
somehow?
No, you can't. The options for looking up in the HashMap<K,V>
are:
entry
method, which requires a K
by value, which in your case is a (String, usize)
- so you'd need to construct a String
.get
, contains_key
etc. all take a "borrowed" form of K
(the documentation says &Q
, where K: Borrow<Q>
; this means either a &(String, usize)
or something that can produced one.Technically you could iterate through it and do your own comparisons, but that's probably not what you want!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With