
📎 This article includes 1 downloadable practice file ↓
Rust is a systems language like C and C++ — it compiles to fast native code — but its compiler prevents whole classes of bugs, such as using memory after it was freed or two threads writing the same data. It has topped developer “most admired” surveys for years, and it is increasingly used in tools you already run: browsers, command-line utilities and operating systems (I am building an experimental one — see Projects).
In this article
Try it without installing
Open play.rust-lang.org and paste the examples. To install locally, use rustup from rust-lang.org; then cargo new hello and cargo run.
Hello, variables
fn main() {
let name = "Atul"; // immutable by default
let mut count = 1; // mut = allowed to change
count += 1;
println!("Hello {name}, count is {count}");
}
Variables cannot change unless you say mut. This small rule catches many accidental overwrites.
Ownership in one example
fn main() {
let a = String::from("report.xlsx");
let b = a; // ownership MOVES to b
// println!("{a}"); // compile error: a was moved
println!("{b}");
let c = b.clone(); // an explicit copy
let len = measure(&c); // & = lend it, do not give it away
println!("{c} has {len} characters");
}
fn measure(s: &String) -> usize {
s.len()
}
Every value has one owner. You can move it, clone it, or borrow it with &. The compiler checks these rules before the program ever runs — that is where Rust’s safety comes from.
A tiny data task
fn main() {
let rows = vec![("North", 12500), ("South", 8400), ("North", 15200)];
let north: i32 = rows.iter()
.filter(|(region, _)| *region == "North")
.map(|(_, amount)| amount)
.sum();
println!("North total: {north}"); // 27700
}
If that looks like the JavaScript filter/map chain, it is — iterators work the same way, but compile to code as fast as a hand-written loop.
📎 Practice files for this article
- 📄All code from this post3 examples in one file, ready to open in your editor.⬇ RS · 1 KB
Free to use for learning. Files with macros (.bas) are plain text — import them with Alt+F11 → File → Import File, and always test on a copy.
Atul (AJ) builds office-automation and local-first AI tools as Atulya AI, and works with Excel, SAP and Oracle EPM every day. He writes about the shortcuts, macros and automations that actually save time — plus the occasional wacky fact. Videos on YouTube: Lazy Automator AI (@LazyAutomatorAI).
More posts by Atul →Stuck on a step? Ask a question and the AI answers using this article.