When executing the file (via the cargo-script wrapper), dependencies are fetched and a binary is compiled on demand (and cached for re-runs).
It's pretty awesome for scripts where type safety is important.
#!/usr/bin/env run-cargo-script
//! This is a regular crate doc comment, but it also contains a partial
//! Cargo manifest. Note the use of a *fenced* code block, and the
//! `cargo` "language".
//!
//! ```cargo
//! [dependencies]
//! time = "0.1.25"
//! ```
extern crate time;
fn main() {
println!("{}", time::now().rfc822z());
}
Then you can just execute it with ./my-script, which will download dependencies, compile and execute.
With https://github.com/DanielKeep/cargo-script you can have single file Rust "scripts" with ecosystem dependencies.
When executing the file (via the cargo-script wrapper), dependencies are fetched and a binary is compiled on demand (and cached for re-runs).
It's pretty awesome for scripts where type safety is important.
Then you can just execute it with ./my-script, which will download dependencies, compile and execute.