Learn Rust: Installing the Toolchain and Writing Your First Industrial Program
What is Rust and Where Does It Fit Among Programming Languages?
Rust is a modern systems programming language developed by Mozilla and officially released in 2015. It sits in the same category as C and C++ — languages that directly control memory and hardware — but adds an unmatched layer of safety: the compiler catches memory bugs before the program ever runs.
In the industrial world, this means software controlling real machines will never crash due to null pointers or memory leaks. Companies like Amazon, Cloudflare, and Dropbox use Rust for their critical infrastructure — and this is why Dr. Machine chose it to build a complete industrial ERP platform.
This lesson is the first in a series of 15 that will take you from zero to building real industrial systems in Rust.
Installing Rust with rustup
rustup is Rust's official installer and toolchain manager. It handles compiler updates and version management automatically.
On Linux and macOS
Open a terminal and run:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
Choose the default option (1) when prompted. After installation, reload your shell environment:
source $HOME/.cargo/env
On Windows
Download and run rustup-init.exe from the official site rustup.rs. You will also need Visual Studio Build Tools because Rust uses the MSVC linker on Windows.
Verifying the Installation
rustc --version
# rustc 1.78.0 (9b00956e5 2024-04-29)
cargo --version
# cargo 1.78.0 (54d8815d0 2024-03-26)
If version numbers appear, the installation was successful.
The Rust Toolchain: rustc, Cargo, and rustfmt
Installing Rust gives you three essential tools:
| Tool | Purpose | When to Use |
|---|---|---|
rustc |
The compiler — converts Rust code to executables | Rarely directly (Cargo calls it) |
cargo |
Project and package manager — build, test, run | Always — your primary tool |
rustfmt |
Automatic code formatter | After every change to unify style |
Cargo is the heart of the Rust development experience. Think of it as npm for JavaScript or pip for Python, but it does more: it builds projects, manages external libraries, runs tests, and generates documentation.
Your First Program: Hello, Factory!
Let us create your first Rust project:
cargo new hello-factory
cd hello-factory
Cargo created a directory containing:
hello-factory/
├── Cargo.toml # Project settings and dependencies
└── src/
└── main.rs # Entry point — main code
Open src/main.rs — you will find:
fn main() {
println!("Hello, world!");
}
Let us modify it to print an industrial message:
fn main() {
let machine_name = "CNC-Mill-07";
let temperature = 42.5;
println!("Hello from machine {}!", machine_name);
println!("Current temperature: {:.1}°C", temperature);
}
Run the program:
cargo run
You will see:
Hello from machine CNC-Mill-07!
Current temperature: 42.5°C
cargo run compiles and runs in one step. To compile without running, use cargo build.
Project Structure: What Did Cargo Create?
Cargo.toml — The Project Identity
[package]
name = "hello-factory"
version = "0.1.0"
edition = "2021"
[dependencies]
# External libraries go here
- name: the project name (becomes the executable name)
- version: version number in SemVer format
- edition: Rust language edition (2021 is the latest stable)
- dependencies: where you add libraries like
tokiofor async programming
The src/ Directory — Source Code
All Rust code lives in src/. The file main.rs is the entry point for any executable program. Later you will learn to split code into multiple modules.
The target/ Directory — Build Artifacts
When building, Cargo creates a target/ directory containing compiled executables and libraries. This directory is not committed to Git (automatically excluded in .gitignore).
Choosing an Editor: VS Code with rust-analyzer
The best Rust development experience today is VS Code with the rust-analyzer extension:
- Install VS Code from code.visualstudio.com
- Open VS Code and install the extension:
rust-analyzer - Open the project folder:
File → Open Folder → hello-factory
What you get:
- Smart autocompletion: suggests functions and types as you type
- Instant error detection: red underlines under incorrect code before compiling
- Type information: hover over a variable to see its type
- Auto-formatting: on save, formats code to Rust's official style
Other useful extensions:
- Even Better TOML: syntax highlighting and completion for
Cargo.toml - Error Lens: displays error messages inline next to the code
Summary
We installed Rust using rustup, explored the essential tools (rustc, Cargo, rustfmt), created our first project, and understood the file structure. Cargo is the engine that manages everything — from building to testing. In the next lesson, we will dive into variables and types — the first building block of any Rust program.