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
rustupaccording to the operating system (Windows / macOS / Linux). - Create a new project with
cargo newand 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 toolcargo, formatterrustfmt, and linterclippyare 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 stringprintln!("{} + {} = {}", 1, 2, 3);— positional argumentsprintln!("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→cargois a standard development environment. - New projects are created with
cargo new <name>,Cargo.tomlandsrc/main.rsare the starting point. cargo runfor execution,cargo checkfor quick check,cargo build --releasefor 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.