Yes it is possible. In Rust, enumoptions (for example EastDirection) are not in the global namespace by default . To create an instance TrafficLight, write:
let mut t1 = TrafficLight {
direction: Direction::EastDirection,
time_elapse: 0,
};
Please note that since variants are not part of the global namespace, you should not repeat the name enumin the variant name. Therefore, it is better to change it to:
enum Direction {
East,
West,
}
/* struct TrafficLight */
let mut tl = TrafficLight {
direction: Direction::East,
time_elapse: 0
};