I have to dynamically build small FSM automata, then run them within the same program. I have no concern about the resource it takes to build them. But I want them to be as efficient as possible when they run.
Since each FSM can be fully determined (number of states, transition, messages signatures, etc). My guess is that the best way to achieve this tradeoff is to produce ad-hoc Rust code for each FSM (with hardcoded states and transitions), compile it down to optimized binary with
rustc then run it as subprocess.
How difficult would it be? How much more difficult would it be if I want to avoid writing source files and binaries to the disk? I guess this would require “in-memory compilation”, with the source code held by a string and the compiled code written to an… executable bytes array? Or maybe a bytes array wrapped into a function or into a trait object?
Is this possible? Why and how?