Rust track

Lesson 01 · Part 1: Basics

Getting Started with Rust

Installing Rust, creating a cargo project and running your first program

Part 1: Basics5 min readFree lesson

Rust is a systems programming language that pursues safety, performance, and productivity at the same time. Because the compiler statically verifies memory safety while achieving C/C-level execution speed, it is widely used in operating systems, web assembly, game engines, CLI tools, and even embedded products.

In this tutorial, you install the Rust toolchain, create your first project with cargo, and then click "Hello, World!" Follow the most basic steps to print . The workflow established here (cargo new → Write code → cargo run) is used the same throughout the remaining 21 episodes.

Learning Objectives

  • Install the Rust toolchain with rustup according to the operating system (Windows / macOS / Linux).
  • Create a new project with cargo new and understand the directory structure.
  • Use the difference between cargo build / cargo run / cargo check.
  • Learn the basic usage of the println! macro and the {} interpolation grammar.

Key concepts

Rust is a relatively young language, with 1.0 released in 2015, but it has been voted the “most loved language” in Stack Overflow developer surveys for several years in a row. It is said to kill three birds with one stone: performance, safety, and concurrency, and has the following features.

  • Memory Safety: Use-after-free, double-free, and data races are blocked at the compile stage without a garbage collector.
  • Zero-cost abstraction: There is almost no runtime overhead even when using traits, generics, and iterators.
  • Rich toolchain: Compiler rustc, Build/Package tool cargo, formatter rustfmt, and linter clippy are provided in one package.

rustup is the Rust version manager. You can manage stable, beta, and nightly versions at once, and upgrading (rustup update) is done in one line.

Windows

Download rustup-init.exe from https://rustup.rs and run it. During installation, if you are notified that Visual Studio Build Tools (C Build Tools) are required, install them as well. Once installed, open a new PowerShell window to see it in action.

macOS

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

After installation, open a new terminal or run source $HOME/.cargo/env to apply PATH.

Linux

You can install it in the same single line as macOS. It can be installed using the distribution package manager (apt, dnf), but the version is often lower, so we recommend using rustup.

Once installation is complete, check operation with the following command:

rustc --version   #compiler version
cargo --version   #package manager version

cargo is responsible for building, dependency management, testing, and document creation.

cargo new hello_rust       #New binary project (library if you add --lib)
cd hello_rust
cargo run                  #Run build
cargo build                #Build only (results in target/debug/)
cargo build --release      #Optimized build (target/release/)
cargo check                #Type check only (fastest)

The basic structure created by cargo new is as follows.

hello_rust/
├── Cargo.toml
├── .gitignore
└── src/
└── main.rs

This is the most common macro that prints a single line to the screen. The reason it has ! is because it is a macro and not a function.

  • println!("Hello, World!"); — simple string
  • println!("{} + {} = {}", 1, 2, 3); — positional arguments
  • println!("Welcome {name}."); — Direct interpolation of same-named variables in Rust 1.58 and higher.

To output without newlines, use print!, and to send to standard error, use eprintln! / eprint!.

See as example

The simplest Rust program. fn main() is the entry point, and outputs one line with the println! macro.

//Part 1 Example 1: Rust's "Hello, World!" Run program
//with `cargo run --bin ex01_hello`.

fn main() {
    //println! is a macro, not a function, so there is a `!` after the name.
    println!("Hello, World!");
    println!("Hello, Rust!");
}

The argument values ​​are entered in order in place of {}. Starting with Rust 1.58, you can directly interpolate variables with the same name, such as {name}.

//Part 1 Example 2: println! Printing variable values with a macro
//Argument values are placed in place of `{}` in order.

fn main() {
    let name = "exponent";
    let year = 2026;

    println!("Name: {}", name);
    println!("Year: {}", year);

    //You can also enter multiple positional arguments.
    println!("Dear {}, you introduced Rust in {}. We’ve started! Welcome", name, year);

    //Short syntax for direct interpolation of variables (Rust 1.58 stable)
    println!("{name}.");
}

Common Mistakes

A. It must be run from within the directory where Cargo.toml is located. Although cargo searches the parent directory to find Cargo.toml, the habit of first moving to the project root and then running it is not confusing.

A: Yes. println is the name of macro, and the macro is always called with !. If you omit !, the compiler generates an error saying, “This function does not exist.”

A. First check whether the source file is saved as UTF-8. If Korean is broken in Windows PowerShell, this can be resolved by changing the console encoding to chcp 65001 or using Windows Terminal.

A. cargo build only builds and leaves a result (target/debug/<name> or .exe). cargo run executes the build at once. cargo run is convenient during development, and just before CI or distribution, an optimized binary is created with cargo build --release.

Cleanup

  • Rust is a system language that takes care of all safety, performance, and productivity, and the flow rustup → cargo is a standard development environment.
  • New projects are created with cargo new <name>, Cargo.toml and src/main.rs are the starting point.
  • cargo run for execution, cargo check for quick check, cargo build --release for distribution build.
  • println! is a macro, so ! is added, and {} Interpolate the values.

Try it yourself

Solve the assignment below. The reference solution is shown below.

Example files

The runnable files used in this lesson. Copy them into your own project and experiment.

src/start_rust/Cargo.tomlTOML
[package]
name = "start_rust"
version = "0.1.0"
edition = "2021"
default-run = "start_rust"

[dependencies]
src/start_rust/src/main.rsRust
//Just run `cargo run` and this guidance message will be displayed.
//Run each example by specifying the bin name as shown below.

fn main() {
    println!("There are two execution examples in this crate.");
    println!();
    println!("  cargo run --bin ex01_hello");
    println!("  cargo run --bin ex02_greet");
}

Assignment

  • File name: homework_01/src/main.rs
  • Key concepts: println! macro, variable interpolation

Requirements

  • Create variables name, hobby, and language and each contain its own value.
  • Print exactly 3 lines with the println! macro.
  • Format: Name: ..., Hobbies: ..., Favorite language: ...

Expected output

Name: Rust Kim
Hobby: Reading books
Favorite language: Rust

Hint

  • Define variables as let, like let name = "Kim Lust"; (see Part 02 for details).

  • Interpolation is possible in either "Name: {}", name or "Name: {name}".

  • File name: homework_02/src/main.rs

  • Key concepts: println! macro, arithmetic expressions

Requirements

  • Define two integers as variables a = 7 and b = 3.
  • Print two lines: sum (a + b) and product (a * b).
  • Format: 7 + 3 = 10, 7 * 3 = 21.

Expected output

7 + 3 = 10
7 * 3 = 21

Hint

  • Defined as let a = 7;, let b = 3;.
  • Like println!("{} + {} = {}", a, b, a + b);, the result of an expression can also be passed as an argument.

Check the correct answer

After solving it yourself, compare it with the reference solution below. The reference solution is annotated with key points and common mistakes.

Show the reference solution

Try the assignment yourself first — comparing your attempt with a working solution is where most of the learning happens.

homework_01/Cargo.tomlTOML
[package]
name = "homework_01"
version = "0.1.0"
edition = "2021"

[dependencies]
homework_01/src/main.rsRust
//Key points:
//- You can bind values to variables with `let`, and interpolate by directly writing the variable name in place of `{}` in `println!`.
//- All sentences must end with a semicolon.

fn main() {
    let name = "Kim Lust";
    let hobby = "Reading books";
    let language = "Rust";

    println!("Name: {name}");
    println!("Hobbies: {hobby}");
    println!("Favorite language: {language}");
}
homework_02/Cargo.tomlTOML
[package]
name = "homework_02"
version = "0.1.0"
edition = "2021"

[dependencies]
homework_02/src/main.rsRust
//Key points:
//- println! The positional argument of `{}` corresponds 1:1 to the values ​​listed later.
//- The result of the expression `a b`, `a * b` is passed as an argument as is.

fn main() {
    let a = 7;
    let b = 3;

    println!("{} + {} = {}", a, b, a + b);
    println!("{} * {} = {}", a, b, a * b);
}

Learn this lesson with a mentor

Work through the Rust track on your own, or join a guided cohort at our Pitampura campus and online.

Call NowEnroll Now