How can I copy an original from its reference?


#1

Hi, I am a Rust newbie.

Here is my failed code.

#[derive(Clone)]
enum SomeEnum { A, B, }

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

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


#2

Works for me. What’s the exact error?


#3

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

I will check my problem.

Thank you for your comment!