If you've ever wanted to whip up a quick script in Rust — just a file, just run it — your wait is almost over. cargo-script, the feature that lets you run a single .rs file with embedded dependencies, just passed its final comment period (FCP) and is tantalizingly close to stabilization.
What It Does
Traditionally, to run Rust code, you need a full project: cargo new, a Cargo.toml, the works. For quick experiments, bug reproducers, or one-off utilities, this overhead is... annoying. Not huge, but enough to reach for Python or just skip the idea entirely.
Cargo script changes that. You write a file:
#!/usr/bin/env cargo
---
[package]
edition = "2024"
[dependencies]
chrono = "0.4"
---
fn main() {
use chrono::Datelike;
let now = chrono::Local::now();
println!("Today is {}-{:02}-{:02}", now.year(), now.month(), now.day());
}
And then you just run it:
./my-script.rs
Cargo parses the front matter (that --- delimited section), downloads the dependencies, compiles, and runs. First run is a bit slower as it fetches crates. Subsequent runs?Milliseconds.
Why This Matters
The use cases are obvious but worth spelling out:
- Bug reproducers become trivial to share. No more "can you set up a crate with these dependencies?" Just paste a single file.
- Prototyping loses its friction. See an interesting algorithm? Want to test it with real data? One file, run it.
- Learning becomes more interactive. You can put a code example in a blog post or book chapter, and readers can just run it.
But there's a subtler shift here: Rust becomes a viable scripting language. Not "systems programming language that can also do scripts" — actually, genuinely usable for the throwaway tasks where you'd reach for Python or Ruby.
The Long Road Here
This feature has existed in various forms for years. The cargo-script crate, cargo-eval, and other workarounds filled the gap. But getting it into Cargo itself? That's been a multi-year effort led by Ed Page.
The tricky part wasn't the feature — it was the details. The Style team needed to settle on formatting conventions. The Lang team had concerns about stray carriage-return characters causing confusion. These aren't sexy problems, but stabilization requires resolving them.
The front matter passed FCP in January 2026. The cargo-script stabilization issue is now in FCP too. Stable release is imminent.
The DX Story
Rust has always had a tension: incredible compile-time guarantees, but at the cost of upfront setup. Cargo script doesn't remove that — the full project structure is still there when you need it. But it removes the barrier when you don't.
This is how a language grows: not just by adding features, but by lowering the cost of entry for small tasks. The next time you have a quick idea, you won't think "I should write this in Python." You'll just write Rust.
And then you'll run it.