citahub / cita_trie

Rust implementation of the Modified Patricia Tree (aka Trie).
Apache License 2.0
71 stars 28 forks source link

feat: implement Clone for MemoryDB #52

Closed Wodann closed 12 months ago

Wodann commented 1 year ago

Performs a deep clone, creating a separate storage

Pencil-Yao commented 12 months ago

https://github.com/citahub/cita-trie/blob/0de727ce4835810dd8d5e6a1ef28d73ae2e3f4da/src/db.rs#L48 Because using Arc wrap map, so we prefer use default clone. If you need deep clone you can add a method to achieve it. Ty for your pr.

Wodann commented 12 months ago

Given that a deep clone can only be made with access to the private member variables, is it okay to add a deep clone method to the public API? If so, what would you like it to be called @Pencil-Yao?

Pencil-Yao commented 11 months ago

Achieve deep copy would not make the storage field be public. Operate MemoryDB object only can use public method, so it's safe, don't worry. I would like the function interface like pub fn deep_copy(&self) -> Self I'm open. @Wodann

Wodann commented 6 months ago

New PR created for deep_clone: https://github.com/citahub/cita_trie/pull/56