'Why does Rust require Copy and Clone traits for simple enum
The following code will not compile unless Copy and Clone traits are derived in the enum. Why is this a requirement given that the enum is basically an i8 and according to the documentation, integers automatically implement the Copy trait? Related to this, since the size of MyEnum should be well known at compile time, shouldn't it go onto the stack? Doesn't the Clone trait imply that it goes on the heap?
#[derive(Debug, Copy, Clone)]
#[repr(i8)]
enum MyEnum {
Some1,
}
fn main() {
let x = MyEnum::Some1;
let y = x;
println!("x={:?} y={:?}", x, y);
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
