orium/rpds

Copy trait for HashTrieMap ?

Closed this issue · 3 comments

Hi.

Really really great library. Thank you for having pointed it out to me on irc (before I got banned for asking a specific question).

Is there any specific reason why the Copy trait is not implemented for HashTrieMap ?

I am in a situation where, to implement the Copy trait on one of my datastructures embedding a HashTrieMap, I have to embed it as a reference, which creates an additional and, I believe, needless lifetime in the type system of my code.

Having had a look at the code of rpds, I do not see a specific reason why the Copy trait could not be implemented, but, as I am quite new to rust, there may be such a reason.

I'd welcome a Copy trait.

Hi. The Copy trait should only be implemented if copying the data structure is very very cheap: usually just copying a few bytes of memory (if you have to call functions inside clone() it is probably too expensive to be Copy). That's not the case for any of the rpds data structures as there is more complex logic when cloning.

I suggest you live with the lifetime if possible. Or otherwise explore other abstractions to share state like Rc/RefCell.

Thank you.

I'll deal with the lifetime, then.

For the wider context and rationale about my inquiry concerning the copy trait for hastriemap:

rust-bakery/nom#1765