Function design_pattern_examples_rust::state::state_exercise
source · pub fn state_exercise() -> Result<(), String>
Expand description
Example of using the “State” design pattern.
The State pattern alters the behavior of an object hierarchy based on some state. This is the basis of a Finite State Machine.
In this exercise, the State struct is a filter that parses text to remove Rust-style line and block comments. It needs to be smart enough to ignore comment characters inside quotes.
The filtering process starts with creating the context that drives the state machine. Internal structs are provided for each state.