Run Rust modules like scripts
runrs
lets you execute Rust source files (*.rs) as if they were compiled binaries or scripts.
$ cat >hello.rs
fn main() {
println!("Hello, world!");
}
^D
$ runrs ./hello.rs
Hello, world!
It can execute any self-contained Rust program, as long as it's a single file with a main
function.
External crates are supported, too! Just make sure the extern crate
declarations are in their usual place.
runrs
creates an ad-hoc binary crate (cargo new --bin
) for each new script it runs.
All those crates live within a single Cargo workspace. This allows them to share their dependencies, avoiding repeated recompilation of common library crates.
- For easier scripting with Rust.
- Because Haskell has
runghc
and Rust shouldn't be worse. - Why not?
This is of course an early prototype and there is clearly a room for improvement:
- handle shebangs correctly
- handle weird crate name abnormalities
(like dash vs. underscore, or stuff like
extern crate crypto;
translating to rust-crypto crate) - better interface (e.g. accept Rust code given via stdin)
- tests!