use std::time::Duration; use std::thread; fn is_the_car_in_place() -> bool { unimplemented!() } fn is_the_bolt_in_place() -> bool { unimplemented!() } fn move_arm_to_new_door() { unimplemented!(); } fn move_arm_to_car() { unimplemented!() } fn turn_bolt() { unimplemented!() } fn grip_door() { unimplemented!() } struct WaitingCar; struct TakingDoor; struct PlacingDoor; struct DoorMachine { state: S, } impl From> for DoorMachine { fn from(st: DoorMachine) -> DoorMachine { while !is_the_car_in_place() { thread::sleep(Duration::from_secs(1)); } DoorMachine { state: TakingDoor } } } impl From> for DoorMachine { fn from(st: DoorMachine) -> DoorMachine { move_arm_to_new_door(); grip_door(); DoorMachine { state: PlacingDoor } } } impl From> for DoorMachine { fn from(st: DoorMachine) -> DoorMachine { move_arm_to_car(); while !is_the_bolt_in_place() { turn_bolt(); } DoorMachine { state: WaitingCar } } } // Will panic fn main() { let beginning_state = DoorMachine { state: WaitingCar }; let next_state: DoorMachine = beginning_state.into(); // Lots of code let last_state: DoorMachine = next_state.into(); }