Compiling rust code from a string and run it

Viewed 259

Is there a way to compile rust code from a string? Something like

use rustc::compile;
let code: &str = r#"fn main() { println!("Hello from Rust!"); }"#;
let result = rustc::compile(code).unwrap();
println!("{}", result);
1 Answers

You need to invoke the Rust compiler. Either with a new process or linking with the compiler libraries.

But compiled programs should not compile code unless they have a very good reason.

Related