The “trait Clone is is not implemented” when deriving the trait Copy for Enum

后端 未结 2 1391
梦谈多话
梦谈多话 2021-02-19 01:43

The following code:

#[derive(Copy)]
enum MyEnum {
    Test
}

Is giving me this error: error: the trait core::clone::Clone is not i

2条回答
  •  -上瘾入骨i
    2021-02-19 02:03

    This happens because the trait Copy, depends on the trait Clone. The compiler will not try to infer and implement the trait for you. So you must explicitly implement the Clone trait as well.

    Like that:

    #[derive(Copy,Clone)]
    enum MyEnum {
      Test
    }
    

提交回复
热议问题