&im::HashMap to im::HashMap

#1
  1. I believe &im::HashMap -> im::HashMap should be very cheap, no more expensive than a Rc::clone()

  2. I can’t figure out how to do the above.

  3. Looking at https://docs.rs/im/12.3.3/src/im/hash/map.rs.html#596-600 there are functions which take a &im::HashMap , does an update, and returns a im::HashMap

  4. Now, suppose I want to do a number of these updates in sequence, I’d like to do:

let mut x: im::HashMap<...> = ...;
for ...
  x = x.update(...)

but I can’t do this right now because I can’t figure out how to convert an &im::hashMap to a im::HashMap

#2

my_map.clone();

1 Like
#3

@sfackler : tried that already. Clone not implemented. :frowning:

#4

https://docs.rs/im/12.3.3/src/im/hash/map.rs.html#1342-1355

1 Like
#5

You’re right. Problem is my Value type did not have impl Clone, so I couldn’t use that.

This also confuses me now – in a persistent hashmap, if everything is shared, why does the value type need to support Clone at all?

#6

It does look like those K: Clone, V: Clone are both unnecessary. It only needs to clone the root with either Ref = Rc or Arc.