-
Notifications
You must be signed in to change notification settings - Fork 16
Open
Description
Given a state-machine like traffic_light.rs, i.e. …
transitions!(Traffic,
[
(Green, Advance) => Orange,
(Orange, Advance) => Red,
(Red, Advance) => Green,
(Green, PassCar) => [Green, Orange]
]
);… it would be nice if machine would auto-generate helper methods on the outer enum type for checking input acceptance …
impl Traffic {
pub fn accepts_advance(&self) -> bool {
match self {
Traffic::Green(_) => true,
Traffic::Orange(_) => true,
Traffic::Red(_) => true,
_ => false,
}
}
pub fn accepts_pass_car(&self) -> bool {
match self {
Traffic::Green(_) => true,
_ => false,
}
}
}… instead of requiring one to implement them manually, as shown in the example (fn can_pass(&self) -> bool).
paaaav and ChaseElectr
Metadata
Metadata
Assignees
Labels
No labels