Is it possible define an enum without worrying about memory allocation in Rust?
Suppose the following is the definition of my enum.
pub enum Orientation {
North,
South,
East,
West,
}
I would like to know whether it is possible to refer to the same instance of say Orientation::North in the code.
Does the following code produce two separate instances of North?
let o1 = Orientation::North;
let o2 = Orientation::North;
I know I can achieve it by defining static variables like below. Is there a better (syntactically safer/simpler/cleaner) way to do the same thing?
pub enum Orientation {
North,
South,
East,
West,
}
static NORTH: Orientation = Orientation::North;
static SOUTH: Orientation = Orientation::South;
static WEST: Orientation = Orientation::West;
static EAST: Orientation = Orientation::East;