Enums in RUST
Enums allow you to define a type by enumerating its possible variants. They can be used to represent things like states or options. Here's an example:
rust
enum TrafficLight {
Red,
Yellow,
Green,
}
fn main() {
let red = TrafficLight::Red;
let yellow = TrafficLight::Yellow;
let green = TrafficLight::Green;
}
No comments:
Post a Comment