Green Computer congress.

5th Grader's Guide to Rust Programming

Cover Image for 5th Grader's Guide to Rust Programming
Karthick Srinivasan Thiruvenkatam
Karthick Srinivasan Thiruvenkatam

Welcome, young programmer! Are you ready to learn about one of the coolest programming languages in the world? Let's dive into Rust!


Table of Contents

  1. What is Programming?
  2. Popular Programming Languages
  3. Introduction to Rust for 5th Graders
  4. Core Rust Concepts for Beginners
  5. Example Programs
  6. Your First Rust Project
  7. How to Install Rust on Mac
  8. How to Install Rust on Windows
  9. How to Program Rust on Your Phone

What is Programming?

The Magic of Talking to Computers

Imagine you have a robot friend who can do anything you ask - but there's a catch! Your robot friend only speaks a special language. Programming is learning to speak that special language so you can tell computers what to do.

What Can You Do with Programming?

When you learn to program, you can:

  • Create video games like Minecraft or Roblox
  • Build websites like YouTube or your favorite game sites
  • Make apps for phones and tablets
  • Control robots and cool gadgets
  • Solve puzzles and math problems super fast
  • Create art and music with code

How Does It Work?

Think of programming like writing a recipe:

  1. You write instructions (this is your code)
  2. The computer reads them (like following a recipe)
  3. The computer does what you asked (makes your program run)

For example, if you wanted to make a simple calculator:

  • You tell the computer: "Take two numbers"
  • Then you say: "Add them together"
  • Finally: "Show me the answer"

And boom! The computer does it instantly!


Just like there are many languages people speak (English, Spanish, Chinese), there are many programming languages! Each one is good at different things.

1. Python ๐Ÿ

  • What it's like: Super friendly and easy to read
  • Good for: Learning to code, making games, AI and robots
  • Fun fact: Named after a comedy show, not the snake!
  • Example: Used by YouTube and Instagram

2. JavaScript โœจ

  • What it's like: Makes websites come alive!
  • Good for: Creating interactive websites and games
  • Fun fact: Runs in every web browser
  • Example: Makes buttons work on websites

3. Scratch ๐ŸŽจ

  • What it's like: Uses colorful blocks instead of typing
  • Good for: First-time programmers (like you!)
  • Fun fact: Made by MIT specifically for kids
  • Example: Perfect for making simple games

4. Java โ˜•

  • What it's like: Very organized and structured
  • Good for: Android apps, big company programs
  • Fun fact: Minecraft was written in Java!
  • Example: Your favorite mobile games

5. C++ ๐Ÿš€

  • What it's like: Super fast and powerful
  • Good for: Games, operating systems, rockets!
  • Fun fact: Used in PlayStation and Xbox games
  • Example: Fortnite and Call of Duty

6. Rust ๐Ÿฆ€

  • What it's like: Super safe and super fast
  • Good for: Programs that need to be reliable and fast
  • Fun fact: Named after a fungus, has a crab mascot named Ferris
  • Example: Used by Firefox, Discord, and Amazon

Introduction to Rust for 5th Graders

What Makes Rust Special?

Imagine you're building with LEGO blocks. Sometimes pieces don't fit together right, and your creation falls apart. Rust is like having magic LEGO blocks that only fit together the RIGHT way!

Why is Rust Cool?

1. Super Safe ๐Ÿ›ก๏ธ

  • Rust catches mistakes BEFORE your program runs
  • It's like having a really smart teacher check your homework
  • You can't accidentally break things

2. Lightning Fast โšก

  • Programs run super quickly
  • Games don't lag
  • Apps respond instantly

3. The Friendly Community ๐Ÿค

  • Rustaceans (Rust programmers) are super helpful
  • Great learning materials made just for beginners
  • Everyone wants to help you learn

The Rust Mascot: Ferris the Crab ๐Ÿฆ€

Rust's mascot is an adorable crab named Ferris! You'll see Ferris everywhere in Rust documentation and community. Why a crab? Because crabs are tough on the outside (safe) but friendly on the inside (easy to use)!

Real Companies Using Rust

  • Discord - Where you chat with friends while gaming
  • Firefox - The web browser
  • Dropbox - Cloud storage
  • Microsoft - Windows and Azure
  • Amazon - AWS cloud services

Core Rust Concepts for Beginners

Let's learn the building blocks of Rust! Don't worry - we'll keep it simple.

1. Variables: Boxes for Storing Stuff ๐Ÿ“ฆ

A variable is like a box where you can store information.

let my_age = 11;
let my_name = "Alex";
let is_raining = false;
  • my_age stores a number (11)
  • my_name stores text ("Alex")
  • is_raining stores true/false (false)

2. Mutability: Can You Change What's in the Box? ๐Ÿ”„

In Rust, boxes (variables) are locked by default. To change what's inside, you need to say mut (which means "mutable" or "changeable"):

let mut score = 0;  // This box CAN be changed
score = 10;         // Now score is 10
score = 20;         // Now score is 20

let name = "Sam";   // This box is LOCKED
// name = "Alex";   // โŒ This would cause an error!

Why? This prevents accidents! If you don't need to change something, Rust makes sure you don't change it by mistake.

3. Data Types: What Kind of Information? ๐ŸŽฏ

Different types of information:

let age: i32 = 11;              // Whole number (integer)
let height: f64 = 4.5;          // Decimal number (float)
let name: String = "Jordan";    // Text
let is_fun: bool = true;        // True or False

4. Functions: Mini-Programs ๐Ÿ”ง

A function is like a mini-program that does one specific job:

fn say_hello() {
    println!("Hello, friend!");
}

fn add_numbers(a: i32, b: i32) -> i32 {
    a + b
}
  • say_hello just prints a message
  • add_numbers takes two numbers and gives you their sum

5. Printing to the Screen ๐Ÿ–จ๏ธ

To show messages on screen:

println!("Hello, World!");
println!("My favorite number is {}", 42);

The {} is like a blank space where you can put a variable!

6. Comments: Notes to Yourself ๐Ÿ“

Comments are notes that the computer ignores. They help YOU remember what your code does:

// This is a comment - the computer ignores this
let age = 11;  // You can also put comments here

Example Programs

Let's write some fun programs! Type these out and see what happens.

Program 1: Hello World! ๐ŸŒ

This is the traditional first program every programmer writes:

fn main() {
    println!("Hello, World!");
    println!("My name is [Your Name]");
    println!("I'm learning Rust!");
}

What it does: Prints three friendly messages to the screen.

Program 2: Math Master ๐Ÿงฎ

fn main() {
    let num1 = 15;
    let num2 = 7;

    let sum = num1 + num2;
    let difference = num1 - num2;
    let product = num1 * num2;
    let quotient = num1 / num2;

    println!("{} + {} = {}", num1, num2, sum);
    println!("{} - {} = {}", num1, num2, difference);
    println!("{} ร— {} = {}", num1, num2, product);
    println!("{} รท {} = {}", num1, num2, quotient);
}

What it does: Does math with two numbers and shows all the answers!

Program 3: Age Calculator ๐ŸŽ‚

fn main() {
    let current_year = 2026;
    let birth_year = 2015;
    let age = current_year - birth_year;

    println!("If you were born in {}, you are {} years old!", birth_year, age);
}

What it does: Figures out how old you are based on your birth year.

Program 4: Temperature Converter ๐ŸŒก๏ธ

fn main() {
    let fahrenheit = 68.0;
    let celsius = (fahrenheit - 32.0) * 5.0 / 9.0;

    println!("{}ยฐF is {:.1}ยฐC", fahrenheit, celsius);
}

What it does: Converts temperature from Fahrenheit to Celsius!

Program 5: Story Generator ๐Ÿ“–

fn main() {
    let hero = "Luna";
    let villain = "The Dark Wizard";
    let treasure = "golden dragon egg";

    println!("Once upon a time, {} went on an adventure.", hero);
    println!("They had to defeat {} to find the {}.", villain, treasure);
    println!("After a brave battle, {} saved the day!", hero);
}

What it does: Creates a mini-story! Change the variables to make different stories.

Program 6: Fun Facts Machine ๐ŸŽฒ

fn main() {
    let fact1 = "A group of flamingos is called a 'flamboyance'";
    let fact2 = "Octopuses have three hearts";
    let fact3 = "Bananas are berries, but strawberries aren't";

    println!("Fun Fact #1: {}", fact1);
    println!("Fun Fact #2: {}", fact2);
    println!("Fun Fact #3: {}", fact3);
}

What it does: Shares cool facts! Add your own favorite facts!


Your First Rust Project: Build a Number Guessing Game! ๐ŸŽฎ

Let's build something really fun - a game where the computer picks a number and you try to guess it!

Step 1: Set Up Your Project

Open your terminal and type:

cargo new guessing_game
cd guessing_game

This creates a new Rust project called guessing_game.

Step 2: Add the Code

Open src/main.rs and replace everything with this code:

use std::io;

fn main() {
    println!("๐ŸŽฎ Welcome to the Number Guessing Game! ๐ŸŽฎ");
    println!("I'm thinking of a number between 1 and 10...");

    let secret_number = 7;  // The computer's secret number

    println!("Can you guess it? Type a number and press Enter:");

    let mut guess = String::new();

    io::stdin()
        .read_line(&mut guess)
        .expect("Failed to read line");

    let guess: i32 = guess.trim().parse().expect("Please type a number!");

    println!("You guessed: {}", guess);

    if guess == secret_number {
        println!("๐ŸŽ‰ You win! That's exactly right!");
    } else if guess < secret_number {
        println!("๐Ÿ“ˆ Too low! The secret number is higher.");
    } else {
        println!("๐Ÿ“‰ Too high! The secret number is lower.");
    }

    println!("The secret number was: {}", secret_number);
}

Step 3: Run Your Game!

In the terminal, type:

cargo run

Step 4: Play!

The game will ask you to guess a number. Type a number between 1 and 10 and press Enter!

Understanding the Code

Let's break down what each part does:

  1. use std::io; - This lets us get input from the keyboard
  2. let secret_number = 7; - The number we're trying to guess
  3. let mut guess = String::new(); - Creates an empty box to store the guess
  4. io::stdin().read_line(...) - Reads what you type
  5. if guess == secret_number - Checks if you guessed right!

Make It Better!

Try these fun modifications:

1. Random Numbers: First, add this to the top of your file:

use rand::Rng;

Add this to Cargo.toml under [dependencies]:

rand = "0.8"

Then change the secret number line to:

let secret_number = rand::thread_rng().gen_range(1..=10);

2. Multiple Guesses: Add a loop so you can guess multiple times until you get it right!

3. Score Tracker: Keep track of how many guesses it takes!


How to Install Rust on Mac ๐ŸŽ

Step 1: Open Terminal

  1. Press Command + Space
  2. Type "Terminal"
  3. Press Enter

Step 2: Install Rust

Copy and paste this command into Terminal:

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

Press Enter and follow the instructions!

Step 3: Configure Your Current Shell

After installation, type:

source $HOME/.cargo/env

Step 4: Check It Worked!

Type this command:

rustc --version

If you see a version number, congratulations! Rust is installed! ๐ŸŽ‰

Step 5: Install a Code Editor

I recommend Visual Studio Code (it's free!):

  1. Go to https://code.visualstudio.com
  2. Download for Mac
  3. Install the "rust-analyzer" extension

How to Install Rust on Windows ๐ŸชŸ

Step 1: Download the Installer

  1. Go to https://rustup.rs
  2. Click "Download rustup-init.exe"
  3. Run the downloaded file

Step 2: Run the Installer

  1. The installer will open a command window
  2. Press 1 then Enter to proceed with installation
  3. Wait for it to complete (this might take a few minutes)

Step 3: Install Visual Studio C++ Build Tools

Rust needs these tools to work on Windows:

  1. The installer will give you a link
  2. Download "Visual Studio Build Tools"
  3. Install the "Desktop development with C++" workload

Step 4: Restart Your Computer

This is important! Restart so Windows knows Rust is installed.

Step 5: Check It Worked!

  1. Press Windows Key + R
  2. Type cmd and press Enter
  3. In the command prompt, type:
rustc --version

If you see a version number, you're all set! ๐ŸŽ‰

Step 6: Install a Code Editor

Download Visual Studio Code:

  1. Go to https://code.visualstudio.com
  2. Download for Windows
  3. Install it
  4. Install the "rust-analyzer" extension

How to Program Rust on Your Phone ๐Ÿ“ฑ

Yes, you can write Rust programs on your phone! Here are the best options:

Option 1: Rust Playground (Web Browser) ๐ŸŒ

Best for: Quick experiments and learning

  1. Open your phone's browser
  2. Go to https://play.rust-lang.org
  3. Start coding right away!

Pros:

  • No installation needed
  • Works on any phone
  • Share your code easily

Cons:

  • Need internet connection
  • Can't make full apps

Option 2: Replit Mobile App ๐Ÿ“ฒ

Best for: Full projects and learning

  1. Download "Replit" app from App Store or Google Play
  2. Create a free account
  3. Tap "+" to create new project
  4. Choose "Rust"
  5. Start coding!

Pros:

  • Full Rust environment
  • Save your projects
  • Works offline (after loading)
  • Can share with friends

Cons:

  • Needs account (but it's free!)

Option 3: Dcoder App (Android Only) ๐Ÿค–

Best for: Android users

  1. Download "Dcoder" from Google Play
  2. Open app
  3. Select "Rust" language
  4. Start programming!

Pros:

  • Made for mobile coding
  • Good for learning
  • Nice interface

Cons:

  • Only on Android
  • Some features need subscription

Option 4: Termux + Rust (Advanced - Android) ๐Ÿ”ง

Best for: Advanced users who want full Rust on phone

  1. Install "Termux" from F-Droid
  2. In Termux, type:
pkg install rust
  1. Use nano or vim to write code

Pros:

  • Real Rust installation
  • Full power
  • Works offline

Cons:

  • More complicated
  • Smaller screen to code on

Tips for Coding on Your Phone ๐Ÿ“

  1. Use landscape mode - More room to code!
  2. Get a bluetooth keyboard - Much easier than typing on screen
  3. Start with small programs - Phone screens are smaller
  4. Use code playgrounds for learning - Perfect for practice
  5. Save your work often - Especially if using browser

Example: Your First Program on Phone

Try this on Rust Playground:

  1. Go to https://play.rust-lang.org on your phone
  2. Clear the default code
  3. Type this:
fn main() {
    println!("I'm coding Rust on my phone!");
    println!("This is awesome! ๐Ÿฆ€");
}
  1. Tap "Run" (or the play button)
  2. See your program work!

Keep Learning! ๐Ÿš€

Congratulations! You now know the basics of Rust programming. Here's how to keep learning:

Great Resources for Kids

  1. Rustlings - Fun exercises to practice Rust

  2. Rust by Example - Learn by looking at code

  3. The Rust Book - The official guide (ask an adult to help)

Project Ideas to Try

  1. Calculator - Make a program that does math
  2. Mad Libs - Story generator with blanks to fill in
  3. Quiz Game - Ask questions and keep score
  4. Random Fact Generator - Show different facts each time
  5. ASCII Art - Make pictures with letters and symbols
  6. Weather Reporter - Show temperature in different scales
  7. Pet Simulator - Virtual pet that needs care
  8. Password Generator - Create strong passwords

Join the Community

  • Rust Discord - Chat with other Rust learners (ask parents first!)
  • r/rust on Reddit - See cool Rust projects
  • Local Coding Clubs - Find other kids learning to code

Final Thoughts

Learning to program is like learning a superpower! With Rust, you're learning one of the most modern and powerful programming languages in the world.

Remember:

  • Everyone makes mistakes - That's how we learn!
  • Start small - Even simple programs are impressive
  • Have fun - Programming should be enjoyable!
  • Ask for help - The Rust community is very friendly
  • Keep practicing - A little bit each day makes you better

Now go build something amazing! ๐Ÿฆ€๐Ÿš€

Happy Coding!