Hello, world

Now before we get into building the Connect-4, let’s get a “Hello, world” program going. This is extremely straightforward as long as you have Rust installed. Here’s the place to start: Rust Installation.

Once you have Rust installed, let’s check the version to verify that the installation worked by running rustc --version in the terminal.

For me the output is rustc 1.90.0 (1159e78c4 2025-09-14), the version might differ for you. But Rust’s backwards compatibility guarantees should ensure the code runs.

Now let’s create an empty folder and a file. As Rust is a compiled language, the folder is useful for co-locating the source code and the compiled artifacts.

mkdir hello_world
cd hello_world
touch hello_world.rs

In the newly created file, let’s write our first function.

// hello_world/hello_world.rs

// 1. entry point
// ↓
fn main() {
//         2. macro
//         ↓
    println!("Hello, world!");
}
1. main function

Every executable Rust program requires an entrypoint, and in ours it’s the main function. Here’s what the Rust book has to say about it:

These lines define a function named main. The main function is special: It is always the first code that runs in every executable Rust program.

As we don’t need the function to return anything, there’s no explicit return type. The implicit return type in Rust is the unit type denoted by (), which is similar to a void in TypeScript.

2. println! macro

Throughout this series, we will use a lot of macros. The syntax can be confusing as it’s similar to a function call, however the key difference is the exclaimation point at the end. The println! macro conveniently hides the machinery that goes into printing a line the the console. It’s similar to the console.log statement in JavaScript.

Rust has other types of macros, I’ll introduce them as we start using them later.

Let’s compile and execute our program:

# hello_world/

rustc ./hello_world.rs
./hello_world

That should print Hello, world! to the terminal! Now that we’ve written our first program, let’s try out the build system that will be used throughout the series.

Cargo

Cargo is the default build system, and package manager for the Rust ecosystem. It sits at the same spot npm (the CLI tool) does in the JavaScript ecosystem.

Let’s create a new project, called hello_universe, but this time using cargo.

cargo new hello_universe
cd ./hello_universe

It should create a structure that looks like:

hello_universe/
├─ src/
│  └─ main.rs                  // entry point
│
└─ Cargo.toml                  // package config and dependencies

The main.rs should already have a main function that prints Hello, world!. I’d like you to update that to print Hello, universe!, and then execute it by running cargo run.

   Compiling hello_universe v0.1.0 (/Users/tauseefk/personal/rust/scratch/hello_universe)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.09s
     Running `target/debug/hello_universe`
Hello, world!

Cargo takes care of compiling the project, and executing it. By default the project gets compiled using a dev profile. The executable lives in target/debug/hello_universe.

We’ll come back to debug/release builds and profiles later. For now this should be enough for us to jump back into writing the Connect-4 game.