By Bhushan Nikhar | Simple Technology
Here's a practical Rust guide for beginners. This guide is written for someone who is freshly trying to learn Rust and wants to understand how to set up, compile, and run basic programs.
Rust is a modern, systems-level programming language focused on performance, safety, and concurrency. It eliminates common bugs such as null pointer dereferencing and data races.
Let’s walk through how Rust code is compiled, executed, and managed using Cargo — its build system and package manager.
The rustc command is the compiler for Rust, and .rs is the file extension for Rust source files.
> rustc main.rs ↩️This compiles the main.rs file using the Rust compiler and produces a binary executable.
The compiled executable file in Rust is machine-architecture specific and does not require a runtime like Java’s JVM.
The executable file typically has no extension.
> ./main ↩️This command runs your compiled Rust program directly.
In Rust, fn main() is the entry point of every program.It’s where program execution begins.
fn main() {
// main method starts program execution in Rust
println!("Hello, world!");
}Rust comes with Cargo — its build system and package manager. It manages dependencies and handles building and running your code efficiently.
> cargo new hello_cargo ↩️This command creates two things:
Cargo.toml — configuration and dependency filesrc folder — contains main.rs with starter codeUse cargo build to compile the Rust project. This will produce the executable file in the target/debug directory by default.
> cargo build ↩️For optimized builds, you can use cargo build --release, which stores the output in target/release.
The cargo run command compiles and runs the program in one step. It’s the most commonly used command during development.
> cargo run ↩️This saves time by avoiding separate build and execute steps.
cargo check verifies if the code compiles successfully without generating an executable. It’s faster than a full build and ideal during development.
> cargo check ↩️Rust provides a powerful combination of speed, safety, and productivity. With rustc and cargo, you can quickly build, test, and manage your projects efficiently.
Once you understand these basic commands and project structures, you’re ready to explore Rust’s ownership model, borrowing, and error handling — the real strengths of the language.
Author: Bhushan Nikhar | Blog: Simple Technology | Category: Rust, Programming Languages, Getting Started