
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).
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.