3 ms·
Dictionary in the python sense? There are two! https://doc.rust-lang.org/std/collections/struct.HashMap.html https://doc.rust-lang.org/std/collections/struct.H
by nicoburns 8y ago
Dictionary in the python sense? There are two!
https://doc.rust-lang.org/std/collections/struct.HashMap.html https://doc.rust-lang.org/std/collections/struct.HashMap.htm...
https://doc.rust-lang.org/std/collections/struct.BTreeMap.html https://doc.rust-lang.org/std/collections/struct.BTreeMap.ht...
- new4thaccount 8y agoAt least the first one seems pretty straightforward and thanks for replying. I only just started and have a lot to learn.
- StavrosK 8y agoOof, I wasted a good hour+ trying to convert from one to the other. Maybe there's an easy way to do this, but not many people on IRC knew (or were available at the time).
- edflsafoiewq 8y agouse std::iter::FromIterator; BTreeMap::from_iter(hash_map.into_iter())
- steveklabnik 8y agoOr .into_iter().collect(), I believe. No import needed.
- a1369209993 8y agoAssuming the keys are Hash + Ord, wouldn't that just be: for (k,v) in &src { dst.insert(k,v); } ?
- StavrosK 8y agoYes, that's what I ended up doing, but the error confused me and I ended up looking for a less hacky way for more than an hour until I said "fuck it" and just did that.
- qbaqbaqba 8y agoAre they compatible?