1. Braces Like C, Types Like ML
If you are brand new to programming, language names like C, Java, or OCaml might sound unfamiliar. Do not worry.
You do not need to know any of those languages to learn Rust.
At first glance, Rust groups instructions inside curly braces ({ }) and ends statements with semicolons (;). On the surface, it looks a lot like mainstream languages such as C, Java, or JavaScript.
When you define data shapes and branch on them, however, its roots in functional languages like SML and OCaml stand out clearly.
Let us briefly compare how other languages organize code. In C, you define a data bundle (a struct) in one place and write the functions that work on it separately.
In C++ and Java, you bundle data and functions together inside a class, then extend behavior through inheritance, where child classes inherit features from a parent class.
Instead of class inheritance, Rust borrowed algebraic data types, pattern matching, and type inference from SML and OCaml.
In fact, the original Rust compiler (rustc) was written in OCaml.1 Add Haskell's type classes and C++'s RAII (a rule that automatically cleans up resources when you are done with them), and you get the Rust we use today.
Those terms sound heavy, but the ideas behind them are simple. Algebraic data types (struct and enum) are blueprints that list the exact shape of your data and every possible state it can hold.
For example, you can declare that an order status must be one of three states: Pending Payment, Shipping, or Delivered.
Pattern matching lets you handle each case directly. If you forget to handle even one case, the compiler catches it before your program ever runs.
Type inference saves you from spelling out whether every value is a number or text, and traits let you attach shared behavior to any data type like snap-on parts.
You do not need to memorize any of these concepts right now. This series starts from the very beginning: printing your first line of text in the terminal.
We start by printing text and the result of a calculation. An order quantity gives us something familiar to work with as we learn the syntax. By the end, you'll have a desktop program that redraws its display when you change a control.
2. Installing rustup and cargo
Before installing anything, let us clarify two basic terms. The code you type in an editor is just plain text for humans; your computer's CPU cannot run it directly.
A compiler is a program that translates that human-readable text into a machine-code file the computer can execute.
A terminal is a window where you type keyboard commands to tell your computer what to do instead of clicking icons with a mouse. On Windows, open PowerShell; on macOS or Linux, open the Terminal app.
Start with Rust's official toolchain manager, rustup. Installing rustup gives you both the Rust compiler (rustc) and the build and package tool (cargo) in one go.2 Cargo is your project manager: it creates new projects, runs your code, and downloads external libraries (called crates in Rust) written by other developers.
On macOS or Linux, copy and paste the first line below into your terminal and press Enter. On Windows, download and run rustup-init.exe from the official website (rust-lang.org). If you choose the default MSVC toolchain on Windows, follow the installer prompts to install the C++ build tools and Windows SDK as well.
A Rust toolchain is the set of tools you build with, including rustc and cargo. On Windows the linker combines the compiled code and the libraries it needs into an .exe.
After installation, reopen your terminal and check both versions with the commands below.
# macOS / Linux
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
# Verify installation (Windows PowerShell / macOS / Linux)
rustc --version
cargo --versionOutput:
rustc 1.98.1 (48a229cea 2026-09-01)
cargo 1.98.1 (797e8a9bc 2026-08-05)Your exact version number and date may differ depending on when you install Rust. If you see a "command not found" error, you probably reused a terminal that was already open before the install.
Close and reopen the terminal so it picks up the newly installed program paths.
If both lines printed without errors, you are ready to go.
To recap: rustc is the compiler that turns .rs source files into machine-code executables, and cargo is the project manager that calls rustc behind the scenes to create, build, run, and manage crates.
3. Creating and Running Your First Project in the Terminal
Open your terminal and navigate to an empty folder where you want to keep your practice projects. Next, create your first Rust project with cargo new.
Then use cd (change directory) to move into the new hello_rust folder and run cargo run.3
cargo new hello_rust
cd hello_rust
cargo runOutput:
Compiling hello_rust v0.1.0
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.42s
Running `target/debug/hello_rust`
Hello, world!cargo new hello_rust created a folder named hello_rust with two key files inside. Cargo.toml is the configuration file that lists your project name, version, and external crates, while src/main.rs is the source file where your actual Rust code lives.
The Project Skeleton: What Cargo Reads and Where the Program Starts
hello_rust/
βββ Cargo.toml
βββ src/
βββ main.rsThe top-level hello_rust folder, the one containing Cargo.toml, is the project root. src is short for source. With the files in these standard places, Cargo can find src/main.rs and build the default executable without more configuration. That's why you run commands from hello_rust but open the file inside src in your editor.4
The starting file and the starting function are two different things. src/main.rs is the first source file Cargo hands to the compiler for this executable. fn main() is where your code starts when the resulting program runs. Another function in the same file won't run on its own; main calls it when it needs it.
The src path is Cargo's convention. Rust syntax doesn't require it: a bin entry in Cargo.toml can specify a different path. We'll stick to the layout above. Edit your source in src/, where it lives, rather than the build output in target/.
cargo run compiles your code into machine code and immediately executes it. In the terminal output, Compiling translates src/main.rs, Finished completes the development (dev) build, and Running launches target/debug/hello_rust to print Hello, world!.
Now open src/main.rs in your code editor. Surprisingly, it contains only three lines.
fn main() {
println!("Hello, world!");
}You might see several unfamiliar symbols here, but each one has a simple job. The keyword fn declares a new function (a named block of code that performs a task).
Next to it, main is the special starting point that Rust always runs first when your program launches.
A function lists its parameters inside the parentheses (). Rust's entry point main takes none, so its parentheses stay empty. You can read command-line arguments inside the function with std::env::args(). The curly braces { } mark where the body begins and ends.
Everything inside them runs in order from top to bottom when main is called.
Inside the braces, println!("Hello, world!"); prints the text inside the double quotes (" ") to the screen and moves to a new line.
The exclamation mark (!) on println! means it is a macro (a special tool that expands into code at compile time) rather than a regular function. For now, it is enough to remember that the tool for printing a line ends with !.
The semicolon (;) at the end works like a period, signaling that this instruction is finished. Forgetting a semicolon is one of the most common beginner mistakes, and it is nothing to stress over.
If you leave one out, the Rust compiler points right to the line where ; is missing.
4. Changing the Terminal Output
Now update src/main.rs to match the code below, save the file, and run cargo run again in your terminal.
If you forget to save (Ctrl+S or Cmd+S) before running cargo run, you will still see the old output, so get into the habit of saving first.
fn main() {
println!("Hello, Rust!");
println!("Item: {}", "tea");
println!("1 + 2 * 3 = {}", 1 + 2 * 3);
}Output:
Hello, Rust!
Item: tea
1 + 2 * 3 = 7The three lines ran in order from top to bottom. The first line prints "Hello, Rust!" as-is and starts a new line.
The {} in Item: {} is an empty slot. The "tea" after the comma fills it, so the program prints Item: tea.
In the third line, Rust evaluates 1 + 2 * 3 first. Just like in math class, multiplication (2 * 3 = 6) happens before addition, so the result 7 fills the {} placeholder.
If the number of {} placeholders does not match the number of values you pass after the comma, the compiler catches the mistake and stops with an error before the program runs.
You now have the core workflow down: edit your code, save the file, and run cargo run in the terminal to see the result.
In Part 2, we will look at variables (let and mut), basic types, and why Rust is built around expressions rather than statements.
Footnotes
- The Rust Reference & Rust History. The initial Rust compiler was implemented in OCaml until it became self-hosting in 2011. https://doc.rust-lang.org/reference/ β©
- The Rust Programming Language (The Book), Ch. 1.1 Installation. https://doc.rust-lang.org/book/ch01-01-installation.html β©
- The Cargo Book (Official Rust build and package manager guide): https://doc.rust-lang.org/cargo/ β©
- The Cargo Book, Package Layout. https://doc.rust-lang.org/cargo/guide/project-layout.html β©