Practical Guide for Rust

By Bhushan Nikhar | Simple Technology

Rust programming language logo and code concept

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 Concepts

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.

Compilation

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.

Execution

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.

Main Method

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!");
}

Cargo New

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 file
  • src folder — contains main.rs with starter code

Cargo Build

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

Cargo Run

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

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 ↩️

Conclusion

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