May 2024

Run a Rust File as a Script with cargo

You can make a script file with rust like this:

---
[dependencies]
anyhow = "1.0.102"
---

use anyhow::Result;

fn main() -> Result<()> {
  println!("Hello, script");
  Ok(())
}
Output:
Hello, script

Old Notes

This was the prior format.

```cargo
[dependencies]
minijinja = { version= "2.0.1", features = ["debug", "loader"] }
```
cargo +nightly -Zscript ./script-name

Notes

  • You have to do ./ in front of the filename if it's not a .rs file.
end of line