Polystate: Composable Finite State Machines in Zig
Polystate is a Zig library for building composable finite state machines through type composition. It enforces programming conventions, recording the state machine's status at the type level and achieving composability via type composition. This improves the correctness of imperative program structures and encourages redesigning the program's state from the perspective of types and composition, thus enhancing code composability. Polystate automatically generates state diagrams, allowing users to intuitively understand program behavior. Examples demonstrate building simple state machines and complex ones through type composition, such as limiting PIN entry attempts in an ATM and reusing selection mechanics in a raylib game. The library leverages type-level programming to achieve conciseness, correctness, and safety.