How can I implement Rust's Copy trait?

后端 未结 2 1402
栀梦
栀梦 2020-12-09 07:21

I am trying to initialise an array of structs in Rust:

enum Direction {
    North,
    East,
    South,
    West,
}

struct RoadPoint {
    direction: Direct         


        
2条回答
  •  有刺的猬
    2020-12-09 08:27

    Just prepend #[derive(Copy, Clone)] before your enum.

    If you really want, you can also

    impl Copy for MyEnum {}
    

    The derive-attribute does the same thing under the hood.

提交回复
热议问题