Using C, at runtime, I can:
- Create the source code of a function,
- Call out to gcc to compile it to a .so (Linux) (or use llvm, etc.),
- Load the .so, and
- Call the function.
Is a similar thing possible in Rust?
In particular I want to use Algebraic Data Types, so using a C subset of Rust's features is not sufficient.
Not yet, officially, though it should be at least possible with not too much hacking. The biggest obstacle is that the libraries do not have any ability to do dynamic loading yet. Here's a potential strategy to make it work (on Rust's incoming branch).
#[no_mangle]
. This should (I haven't tried it) produce an unmangled symbol name so it's easy to find.sys::Closure
).Rust also has a minimally-tested JIT that can be used for this type of thing, but it has some major bugs.