Complex state machines

A more complex state machine, that allows you to move from one to another in your code while still using the type system to check for proper usage, can be done. Let's start by defining the state machine. We want a machine that represents the way a robot works in a car-building facility. Let's say its job is to install two doors in a car. It will first wait for the next car to come, take the door, put it in place, put the bolts in place, do the same for the second door, and then wait for the next car.

We will first define some functions that will use sensors and that we will simulate:

fn is_the_car_in_place() -> bool {    unimplemented!()}fn is_the_bolt_in_place() -> bool {    unimplemented!()}fn move_arm_to_new_door() {

Get Rust High Performance now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.