100 days of Rust - day 1
Day 1 of Learning Rust: Getting Started with the Basics
Hey friends! Welcome to my series on learning Rust in 100 days. Over the next 100 days, I'll share what I've learned each day, explain key concepts so you can follow along, provide helpful resources, and even create a GitHub repo where we can collaborate. Feel free to create issues there to request more resources, share your progress, or ask questions.
Today, we'll start with the basics: installing Rust on your system (it works on macOS, Linux, or Windows). We'll also cover a quick introduction to Rust, set up a simple project, and run your first "Hello, World!" program. By the end, you'll officially be a Rustacean (that's what Rust enthusiasts call themselves)! 🦀
What is Rust?
Before we dive in, let's add some context. Rust is a modern systems programming language designed for performance, reliability, and safety. It prevents common bugs like null pointer dereferences, data races, and buffer overflows through its ownership system, borrow checker, and strong type system—all at compile time, without sacrificing speed. It's great for web assembly, embedded systems, CLI tools, and even replacing C/C++ in performance-critical apps. Companies like Mozilla, AWS, and Microsoft use it extensively. If you're coming from languages like C++, Python, or JavaScript, Rust might feel strict at first, but it teaches you to write safer code.
For more depth, check out the official Rust book: The Rust Programming Language—it's free and beginner-friendly.
Installing Rust
Rust uses a tool called rustup for installation and management. It handles multiple Rust versions (stable, beta, nightly) and sets up everything you need, including the compiler (rustc), package manager (cargo), and documentation tools.
On macOS or Linux:
- Open your terminal and run:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh - Follow the prompts. It will download and install Rust, and automatically configure your environment variables (like adding Cargo to your PATH).
- Restart your terminal after installation.
On Windows:
- Go to the official site: https://www.rust-lang.org/tools/install.
If you can't find the installer, try this alternative link: https://forge.rust-lang.org/infra/other-installation-methods.html. - Download and run the
rustup-init.exeinstaller. - Follow the instructions—it will set up Rust and add it to your PATH automatically.
- Use PowerShell or Command Prompt for the rest of this guide.
After installation, verify it worked by running:
rustc --version
You should see something like rustc 1.82.0 (or whatever the latest version is). No need to manually configure environment variables—rustup handles that for you.
If you run into issues, refer to the official installation guide: https://www.rust-lang.org/learn/get-started.
Setting Up Your Development Environment
Choose an IDE or editor you're comfortable with. I recommend Visual Studio Code (VS Code) because it's free, lightweight, and has excellent Rust support:
- Download VS Code from https://code.visualstudio.com.
- Install the
rust-analyzerextension (search for it in the Extensions tab). It provides auto-completion, error checking, and debugging right in the editor.
Alternatives: IntelliJ IDEA with the Rust plugin, Vim/Neovim with rust.vim, or even just a text editor like Notepad++ if you're starting simple.
Congrats! You're now officially a Rustacean. 🦀
Your First "Hello, World!" Project
Let's create and run a simple program to print "Hello, World!" This introduces Cargo, Rust's build system and package manager.
What is Cargo?
Cargo is Rust’s official build system and package manager. It handles:
- Creating new projects with a standard structure
- Building your code (uses
rustcunder the hood) - Downloading and managing dependencies (called crates) from https://crates.io
- Running tests, benchmarks, and generating documentation
- Packaging your project for distribution
Project metadata lives in a Cargo.toml file (similar to package.json in Node.js or pom.xml in Maven). Cargo ensures builds are repeatable, reliable, and easy to share.
Learn more: https://doc.rust-lang.org/cargo
Steps to Create Your First Rust Project
- Open a terminal (PowerShell on Windows, Terminal on macOS or Linux).
- Create a directory for our Rust journey:
mkdir RustJourney cd RustJourney - Create a new project using Cargo:
Cargo generates this structure:cargo new hello_world cd hello_worldsrc/main.rs→ main source fileCargo.toml→ project configuration.gitignore→ Git ignore rules
- Open
src/main.rs. Cargo pre-fills it with:
Explanation:fn main() { println!("Hello, world!"); }fn main()→ entry point of every Rust executableprintln!→ a macro (note the!) that prints to the console;ends statements (Rust is strict)- 4 spaces indentation is the convention
- Build and run the project:
Output:cargo run
Build without running:Hello, world!
Optimized release build:cargo buildcargo build --release
Congrats! You’ve completed your first Rust project. If you see errors, don’t panic—Rust’s compiler messages are very helpful.
Resources
- 📘 Rust by Example
- 💬 Community: r/rust (Reddit), Rust Discord
- GitHub Repo for Day 1: https://github.com/Dawaman43/100-days-of-rust/tree/main/days/days-01-20/day-01
Summary
- Installed Rust using
rustup - Learned what Cargo is
- Created a Hello World project
- Ran Rust code with
cargo run
Practice
Change "Hello, world!" to print your name. Share your progress in the GitHub repo! 🚀