HelloWorld.rs

by Abi

Rust is consistently voted one of the most loved programming languages. It offers the speed of C++ without the memory-safety headaches. If you're ready to take your first steps, you're in the right place — by the end of this post you'll have Rust installed and your first program running.

Why Rust?

  • Memory safety — Rust prevents whole classes of bugs (null-pointer dereferences, data races) at compile time, with no garbage collector.

  • Blazing speed — it compiles straight to native machine code, so it runs as fast as C/C++.

  • Great tooling — the built-in package manager and build tool, Cargo, makes projects a breeze.

Step 1 — Install Rust

The official installer is rustup. On Linux or macOS, run:

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

On Windows, download rustup-init.exe from rustup.rs. Then verify your install:

rustc --version

Step 2 — The Code

Every journey begins with a single line. In Rust, your introduction looks like this:

fn main() {
    println!("Hello, world!");
}

Breaking Down the Code

  • fn main() — defines a function named main, the entry point of every Rust program. Execution always starts here.

  • println! — the ! marks this as a macro, not a function. Macros run at compile time and can take a variable number of arguments; this one prints a line of text to the screen.

  • The semicolon ; — ends the statement.

Step 3 — Run It

Option A — quick single file

  1. Save the code above as main.rs.

  2. Compile it: rustc main.rs

  3. Run the result: ./main (Linux/macOS) or .\main.exe (Windows).

Option B — the real way (Cargo)

For any actual project, use Cargo, Rust's build system and package manager:

cargo new hello_world
cd hello_world
cargo run

Cargo generates a ready-to-run “Hello, world!” in src/main.rs, then builds and runs it. You'll see:

   Compiling hello_world v0.1.0 (/path/to/hello_world)
    Finished dev [unoptimized + debuginfo] target(s)
     Running `target/debug/hello_world`
Hello, world!

Where to Next

Congratulations — you've installed Rust and run your first program. The road ahead is Rust's signature feature: ownership, the compile-time discipline (alongside its strict type system) that delivers memory safety without a garbage collector. That's where Rust really starts to click.