Series: Learn Rust from Scratch | Post 1 of 11
Introduction
Welcome to the Learn Rust from Scratch series on CodeWithNeo! Over 11 posts, we'll take you from a complete beginner to a confident Rust developer. By the end of this series, you'll understand Rust's ownership system, data types, control flow, functions, structs, error handling, and much more.
In this first post, we answer the big questions: What is Rust? Why should you care? And how do you write your first program?
What Is Rust?
Rust is a systems programming language created by Mozilla Research. It first appeared in 2010 and released its stable 1.0 version in 2015. Since then, it has won the title of "Most Loved Programming Language" in the Stack Overflow Developer Survey for eight consecutive years.
Rust is designed around three core promises:
| Promise | What It Means |
|---|---|
| Safety | No null pointer crashes, no buffer overflows, no data races |
| Speed | Performance comparable to C and C++ |
| Concurrency | Write multi-threaded code without fear |
Unlike languages like Python or JavaScript that use garbage collectors to manage memory, Rust uses a unique ownership system that enforces memory safety at compile time — with zero runtime overhead.
What Makes Rust Different?
Most languages force you to choose between safety and performance. Rust breaks that trade-off.
- C/C++ give you raw speed but are full of memory bugs (use-after-free, null dereferences).
- Python/JavaScript are safe and easy but much slower.
- Rust gives you C-level speed and memory safety — guaranteed by the compiler.
Think of Rust's compiler as your strictest, most helpful colleague. It will refuse to compile your code if it finds a potential memory error. At first this feels annoying; soon it feels like a superpower.
Installing Rust
Rust uses a tool called rustup to manage installations.
Step 1 — Install rustup
On Linux / macOS:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
On Windows:
Download and run rustup-init.exe from https://rustup.rs.
Follow the on-screen prompts. When done, close and reopen your terminal.
Step 2 — Verify the installation
rustc --version
cargo --version
You should see output similar to:
rustc 1.78.0 (9b00956e5 2024-04-29)
cargo 1.78.0 (ba5b40a74 2024-04-18)
Two tools are now available to you:
rustc— the Rust compilercargo— Rust's build system and package manager (you'll use this for everything)
Your First Rust Program
Let's create a proper Rust project using Cargo.
Step 1 — Create a new project
cargo new hello_rust
cd hello_rust
Cargo generates this directory structure:
hello_rust/
├── Cargo.toml ← Project metadata and dependencies
└── src/
└── main.rs ← Your source code
Step 2 — Look at the generated code
Open src/main.rs. Cargo already wrote a Hello World for you:
fn main() {
println!("Hello, world!");
}
Let's break this down line by line:
| Code | Meaning |
|---|---|
fn main() |
Declares the main function — every Rust program starts here |
{ ... } |
Curly braces define the function body |
println!("Hello, world!") |
Prints text to the screen. The ! means it's a macro, not a regular function |
; |
Rust statements end with a semicolon |
Step 3 — Run the program
cargo run
Output:
Compiling hello_rust v0.1.0
Finished dev profile [unoptimized + debuginfo]
Running `target/debug/hello_rust`
Hello, world!
That's it — you just compiled and ran your first Rust program!
Let's Customize It
Modify src/main.rs to be a little more interesting:
fn main() {
// Declare a variable to hold our name
let name = "Neo";
// Declare a variable to hold our age
let age = 25;
// println! can format values using {} placeholders
println!("Hello! My name is {} and I am {} years old.", name, age);
// You can also use named placeholders
println!("Welcome to {blog}, the best place to learn Rust!", blog = "CodeWithNeo");
}
Run it again:
cargo run
Output:
Hello! My name is Neo and I am 25 years old.
Welcome to CodeWithNeo, the best place to learn Rust!
Key things to notice:
letis how you declare variables in Rust{}inside a string is a placeholder that gets filled with a value//starts a single-line comment- Variables are immutable by default in Rust (we'll explore this in Post 2)
Understanding Cargo.toml
Open Cargo.toml. It looks like this:
[package]
name = "hello_rust"
version = "0.1.0"
edition = "2021"
[dependencies]
[package]— basic metadata about your projectname— the project nameedition— which edition of Rust to use (always use2021for new projects)[dependencies]— where you'll list external libraries (called crates) your project needs
Useful Cargo Commands
Throughout this series you'll use these regularly:
# Create a new project
cargo new project_name
# Compile and run your project
cargo run
# Just compile (without running)
cargo build
# Check your code for errors without producing a binary (fast!)
cargo check
# Run tests
cargo test
# Format your code automatically
cargo fmt
# Check for common mistakes and improve your code
cargo clippy
Summary
In this post you learned:
- ✅ What Rust is and why it's valued for safety + performance
- ✅ How to install Rust using
rustup - ✅ How to create a new project with
cargo new - ✅ The structure of a basic Rust program
- ✅ How
println!works with placeholders - ✅ Essential Cargo commands
What's Next?
In Post 2, we'll dive into Variables, Data Types, and Mutability — the foundation of every Rust program. You'll learn why Rust makes variables immutable by default, the difference between scalar and compound types, and how Rust's type system protects you from bugs.
Next Post: Variables, Data Types, and Mutability in Rust →
Part of the Learn Rust from Scratch series on CodeWithNeo


Leave a Reply