How can I copy an original from its reference?


Hi, I am a Rust newbie.

Here is my failed code.

enum SomeEnum { A, B, }

fn func(vm: &VecMap<SomeEnum>, p: SomeEnum, index: usize) -> VecMap<SomeEnum> {
    let mut result = vm.clone();
    result.insert(index, p);

I wanted result as VecMap, but compiler says that vm.clone() is &VecMap.
How can I copy the original from its reference?


Works for me. What’s the exact error?


Sorry, I was confused when I tried simple reproduction code.

I will check my problem.

Thank you for your comment!