Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

🦀 The Land of Rust: Ferris the Crab’s Space Adventures

Chapter 1: Ferris, the Space Crab, and the Lost Toolbox (Installation & Hello World)

📋 Chapter Outline:


1.1. The Adventure Begins!

1.1.1. Meet Ferris

Hello, friend! 👋 My name is Ferris. I’m a cute space crab from the planet “Crab”! 🦀🚀

My spaceship crash-landed right in your backyard a few nights ago. (Yes, those weird noises you heard… that was me!)

Now my ship is wobbling. The engines are off, the navigation screen is black, and the only thing still working is an old Earth computer. 💻

I need to talk to this computer to fix my ship. But here’s the problem: Earth computers only understand certain languages. One of those languages is Rust.

💡 Fun Fact: The word “Rust” in English means corrosion. But don’t worry! This language is neither rusty nor old. Actually, it’s one of the newest, fastest, and safest languages in the world! ✨

[Illustration: A cheerful red-shelled crab with large expressive eyes stands on two legs beside a retro computer monitor. The screen displays glowing green text reading “Earth, I am here!” The background shows a slightly messy spaceship interior with a round window revealing a starry sky. The art style is vibrant and warm, perfect for children’s books.]

1.1.2. Why Does Ferris Need a New Language?

You might ask: “Don’t computers understand my language?” 😄

No, my friend! Computers only understand zeros and ones. And we humans can’t speak in zeros and ones! That’s why engineers created programming languages—to be a bridge between what we say and what computers understand.

Rust is one of the best bridges:

  • ⚡ It’s super fast
  • 🛡️ It’s super safe (it won’t let your program suddenly freeze or crash!)
  • 🎮 Big companies like Google, Microsoft, and even game developers use it

And most importantly: Rust teaches you to think like an engineer. I use Rust on all my space travels to keep my ship safe and avoid getting lost in space! 🌌

[Illustration: A laptop screen shows a split view: on the left side are zeros and ones, on the right side are colorful code blocks. A small friendly crab mascot sits on the keyboard pointing at the code. The background shows a simple desk with a coffee mug, notebook, and a tiny toy rocket. Clean, bright, educational style.]

1.1.3. Ferris at the Terminal

[Illustration: A wide scene showing Ferris the red crab sitting in front of a dark terminal screen, typing with his claws. Glowing code lines reflect on his shell. Floating around him are tiny cartoon spaceships, stars, and gears. The style is whimsical and colorful, with high-quality children’s book illustration and cinematic lighting.]


1.2. The Magic Toolbox: Installing rustup

To speak Rust to the computer, we first need to install a magic toolbox called rustup. This toolbox contains three important things:

🔹 Compiler (rustc): Like a translator robot, it converts our words into zeros and ones. 🔹 Package Manager (cargo): A smart assistant that handles repetitive tasks for us (we’ll meet it soon). 🔹 Local Documentation: A complete handbook that’s always available offline.

📌 Before We Start: In this chapter, we’ll use a special window called the Terminal. The terminal is a black screen where we can type text commands to tell the computer what to do.

To open it:

  • Windows: Press Start, type cmd, and click on Command Prompt.
  • Mac: Press Command + Space, type Terminal, and press Enter.
  • Linux: Press Ctrl + Alt + T together.

Now, let’s install!

1.2.1. Go to rustup.rs

Open your browser (Chrome, Firefox, whatever you have). In the address bar, type:

https://rustup.rs

and press Enter. A page like this will appear:

[Illustration: A close-up of a laptop screen displaying the rustup.rs homepage. A large, inviting blue “Download” button is visible. A tiny cartoon crab logo peeks from the corner of the browser window. The background shows a clean, minimal desk setup with soft pastel lighting. Modern educational illustration style with clear UI focus.]

1.2.2. Click the Download Button

Click on the big blue button that says Download. The installer for your Windows, Mac, or Linux will start downloading.

📌 Note for Grown-ups: On Windows, a file named rustup-init.exe will download. On Mac and Linux, you’ll receive a shell script.

1.2.3. Run the Downloaded File

🪟 Windows:

  • Go to your Downloads folder and double-click the file. A black window (the terminal) will open.

🍎 Mac:

  • Open Terminal. Then type these commands one by one and press Enter:
cd Downloads
sh rustup-init

(If you see a “permission denied” message, first run chmod +x rustup-init, then run sh rustup-init again.)

🐧 **Linux **(like Ubuntu)

  • Open Terminal with Ctrl+Alt+T. Then type:
cd Downloads
chmod +x rustup-init
./rustup-init

1.2.4. Choose Default Installation

After running, a text menu will appear. Just type 1 (for “Proceed with installation”) and press Enter.

Now wait a few seconds… Green lines will rain down the screen like magic. When you see this message:

Rust is installed now. Great!

You’re all done! 🎉

1.2.5. Verify the Installation

To make sure everything works, type this in the same terminal:

rustc --version

You should see something like:

rustc 1.85.0 (4d91de4e4 2025-02-17)

(The numbers might differ; what matters is that you don’t see a red error!)

Do the same for cargo:

cargo --version

If both commands show a version number, your magic toolbox is ready to go! 🛠️✨

[Illustration: A terminal window with dark background and bright green success text “Rust is installed now. Great!” Next to the screen, Ferris the crab is doing a happy little dance, holding a tiny wrench. The desk has a small lamp and a notebook. Cheerful, cartoon, educational style with vibrant colors.]


1.3. Our First Words to the Computer: Hello, World

Now that we have the toolbox, let’s say our first sentence to the computer. We’re going to write: “Earth, I am here!

1.3.1. Create the Adventure Folder

Create a new folder on your computer named majara. This will be the home for all our programs in this book.

You can create it with your mouse, or type these two commands in the terminal:

mkdir majara
cd majara

(mkdir means “make directory/folder”, and cd means “change directory/go into this folder”.)

1.3.2. Open a Text Editor

We need a magic notebook to write our code. You can use Notepad (Windows) or TextEdit (Mac), but it’s much better to install a dedicated editor. I recommend VS Code (free and excellent).

Download it from code.visualstudio.com. After installing, open it and open the majara folder (File → Open Folder).

[Illustration: A child’s hand clicking “Open Folder” in VS Code interface. The folder name “majara” is highlighted in blue. Ferris the crab peeks curiously from behind the monitor. Semi-realistic cartoon style with warm lighting, educational tone.]

1.3.3. Write the Magic Code

In VS Code, create a new file (Ctrl+N) and type this code exactly:

fn main() {
    println!("Earth, I am here!");
}

1.3.4. Line-by-Line Explanation

Let’s look at each line carefully:

Line 1: fn main() {

  • fn is short for “function”.
  • main is a special name that the compiler knows is where the program should start.
  • The parentheses () are empty for now because we’re not giving it any information yet.

Line 2: println!("Earth, I am here!");

  • Four spaces (or one Tab) at the start mean: “This command is inside the main function.”
  • The ! after println means this is a magic spell that does something special (displays text on screen).
  • ln means “after printing, go to the next line.”

Line 3: }

  • The closing brace. It means the function is finished.

1.3.5. Save the File

Save the file as main.rs inside the majara folder. The .rs extension stands for Rust.

⚠️ Important: The filename must be main.rs. When Rust sees main, it knows where the program starts.

1.3.6. Compile and Run

Now we need to convert our code into zeros and ones. The compiler does this.

Open the terminal (if it’s closed) and go into the majara folder. To navigate, use cd with the folder path. For example, if majara is on your Desktop:

cd Desktop/majara

(If you’re unsure about paths, ask a parent for help.)

Then type:

rustc main.rs

Wait a moment. If there’s no error, a new file named main (or main.exe on Windows) will be created. Now run it:

  • 🪟 Windows: main.exe
  • 🍎🐧 Mac/Linux: ./main

1.3.7. See the Result

💥 Boom! The screen displays:

Earth, I am here!

Congratulations! 🎉 You just wrote and ran your first Rust program. Ferris is so excited to see this message!

[Illustration: Ferris the crab jumping joyfully in front of a terminal screen that displays “Earth, I am here!” Colorful confetti and tiny stars float around. The background shows a cozy desk with a mug and notebook. Vibrant, celebratory children’s book illustration with high energy.]


1.4. My Smart Helper: Cargo

So far, we built our program manually with rustc. But for bigger projects, we need a smart assistant to handle repetitive tasks. Its name is Cargo. 📦🤖

1.4.1. What Is Cargo?

Cargo does three important things for us:

  1. Creates project structure (folders and initial files).
  2. Manages dependencies (libraries written by others).
  3. Builds and runs programs easily (with a single simple command!).

1.4.2. Create a New Project with Cargo

Let’s create a new project. Go to a clean folder (like your Desktop) and type in the terminal:

cargo new hello_ferris
cd hello_ferris

Cargo creates a folder named hello_ferris containing:

hello_ferris/
├── Cargo.toml
├── src/
│   └── main.rs
└── .gitignore

(Don’t worry about .gitignore for now; you’ll learn about it later.)

[Illustration: A clean infographic-style illustration showing a folder tree: hello_ferris/ containing Cargo.toml and src/main.rs highlighted in bright colors. Ferris the crab stands beside it pointing like a tour guide. Modern, educational, vector-based style.]

1.4.3. Meet Cargo.toml

Open the Cargo.toml file. You’ll see something like this:

[package]
name = "hello_ferris"
version = "0.1.0"
edition = "2024"

[dependencies]

🔹 [package]: Your project’s ID card (name, version, and year standard). 🔹 [dependencies]: Here we’ll later write the names of helper libraries (it’s empty for now).

This file is also called the “project manifest.” Every Rust project must have a Cargo.toml.

1.4.4. Meet the src Folder

All our code must go inside the src folder. Cargo already placed a ready-made main.rs:

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

(Yes! Exactly the same code we wrote, just in English.)

1.4.5. Run with cargo run

Now you don’t need to manually run rustc. Just type this in the terminal (inside the hello_ferris folder):

cargo run

Cargo does these things automatically:

  • ✅ Checks if the code has changed.
  • ✅ Compiles if needed.
  • ✅ Runs the program.

You’ll see the output:

Hello, world!

Quick and easy, right? 😎

[Illustration: Cartoon illustration of Ferris the crab pressing a big green button labeled “cargo run”. Next to him, a terminal screen pops up showing “Hello, world!” Speed lines and sparkles emphasize quick action. Fun, dynamic, children’s book style.]

1.4.6. Difference Between cargo build and cargo run

🔹 cargo run = Compile + Run (when you want to see the result immediately). 🔹 cargo build = Compile only (creates an executable in target/debug/, without running).

💡 A note for when you grow up: If you run cargo build --release, you’ll get a faster, optimized output (but it takes longer to build). We don’t need that for now.

1.4.7. Exercise: Change the Message

Now let’s change the text. Open src/main.rs and instead of "Hello, world!", write:

#![allow(unused)]
fn main() {
println!("Hello Ferris! Welcome to Earth!");
}

Save it and run cargo run again. Now the output is:

Hello Ferris! Welcome to Earth!

Well done! You’re now friends with Cargo. 🤝


1.5. Summary & Challenge

1.5.1. What We Learned

In this chapter, you learned:

  • ✅ Who Ferris is and why we need Rust.
  • ✅ How to install rustup.
  • ✅ How to write a main.rs file and compile it with rustc.
  • ✅ How to create a project with cargo new and run it with cargo run.
  • ✅ The meaning of fn main(), println!, braces, and semicolons.

1.5.2. New Terms Glossary

Let’s review some new words:

TermSimple MeaningEmoji
CompilerA robot that translates our code into zeros and ones🤖
Source CodeThe text we write (like main.rs)📝
TerminalThe black screen where we type commands
RunWhen we turn on the program to make it work▶️
**Magic Spell **(Macro)A command with ! that does special things

1.5.3. Small Challenge

Now it’s your turn, champion! 🏆 Complete these missions:

  • 1️⃣ Use cargo new to create a project named my_first_program.
  • 2️⃣ In src/main.rs, write: "I'm learning to code!"
  • 3️⃣ Run it with cargo run and see the result.
  • 4️⃣ (Optional) Write two println! lines in a row:
fn main() {
    println!("Hello!");
    println!("I'm Ferris. 🦀");
}

See what happens.

If you can do these, you’re totally ready for the next chapter! In Chapter 2, we’ll build a “Guess the Number” game where the computer picks a number and you have to guess it. Exciting, right? 😉

💬 Remember: Every great programmer started with “Hello, World.” You’ve just taken your first step! 🚀

[Illustration: A child sitting at a desk looking happily at a computer terminal with a big green checkmark on screen. Ferris the crab stands on the desk giving a thumbs up. Floating text “Good luck!” in playful font above. Encouraging, bright, cartoon children’s book illustration style.]


🔚 End of Chapter 1