从字符串和 运行 编译 rust 代码
Compiling rust code from a string and run it
有没有办法从字符串编译 rust 代码?像
use rustc::compile;
let code: &str = r#"fn main() { println!("Hello from Rust!"); }"#;
let result = rustc::compile(code).unwrap();
println!("{}", result);
您需要调用 Rust 编译器。使用新进程或与编译器库链接。
但是除非有充分的理由,否则编译程序不应编译代码。
有没有办法从字符串编译 rust 代码?像
use rustc::compile;
let code: &str = r#"fn main() { println!("Hello from Rust!"); }"#;
let result = rustc::compile(code).unwrap();
println!("{}", result);
您需要调用 Rust 编译器。使用新进程或与编译器库链接。
但是除非有充分的理由,否则编译程序不应编译代码。