Rust Programming Language

Rust — Complete Tutorial

Learn Rust from absolute zero. Every topic explained simply with real examples you can edit and understand quickly.

🟩 Beginner Friendly ▶ Live Code Editor 📚 29 Topics
Your Progress3% complete
Live Rust Lab

Edit the Rust example below and click Run to preview expected output notes.

rust-lab.rs
📝 Edit Code
👁 Live Preview
💡 Try this: modify values and method logic, then run again.
∙ Chapter 001

Rust Tutorial

Learn Rust Tutorial with a small example you can edit and run.

📝Syntax
cargo new my-app
cargo run
Example (Edit & Run)

Edit the Rust code below and click Run. The output panel shows the extracted Expected Output notes (or simple prints).

tutorial.rs
📝 Edit Code
👁 Output
💡 Tip: keep a // Expected Output: line so the output panel has something to show.
🔍Line-by-line
LineMeaning
fn main() {Program entry point.
println!("Welcome to Rust");Print macro outputs text.
}Rust line.
🏢Real-world
  • 1Rust is used for performance-critical and reliability-focused software.
Common Mistakes
  • 1Fighting the borrow checker instead of learning ownership rules.
Best Practices
  • 1Model ownership clearly and keep functions small.
📖Summary & Practice
  • 1Edit the example and rerun to learn faster.
  • 2Prefer clarity first; optimize later.
💡Practice: answer the questions below, then modify the example to match your answers.
  • 1Change one value and predict the output.
  • 2Add one edge case and handle it.
  • 3Explain the rule in 1 sentence.
📈SEO

Keywords (topic intent):

Rust Systems Rust Tutorial
∙ Chapter 002

Rust HOME

Learn Rust HOME with a small example you can edit and run.

📝Syntax
cargo new my-app
cargo run
Example (Edit & Run)

Edit the Rust code below and click Run. The output panel shows the extracted Expected Output notes (or simple prints).

home.rs
📝 Edit Code
👁 Output
💡 Tip: keep a // Expected Output: line so the output panel has something to show.
🔍Line-by-line
LineMeaning
fn main() {Program entry point.
println!("Welcome to Rust");Print macro outputs text.
}Rust line.
🏢Real-world
  • 1Rust is used for performance-critical and reliability-focused software.
Common Mistakes
  • 1Fighting the borrow checker instead of learning ownership rules.
Best Practices
  • 1Model ownership clearly and keep functions small.
📖Summary & Practice
  • 1Edit the example and rerun to learn faster.
  • 2Prefer clarity first; optimize later.
💡Practice: answer the questions below, then modify the example to match your answers.
  • 1Change one value and predict the output.
  • 2Add one edge case and handle it.
  • 3Explain the rule in 1 sentence.
📈SEO

Keywords (topic intent):

Rust Systems Rust HOME
∙ Chapter 003

Rust Intro

Learn Rust Intro with a small example you can edit and run.

📝Syntax
cargo new my-app
cargo run
Example (Edit & Run)

Edit the Rust code below and click Run. The output panel shows the extracted Expected Output notes (or simple prints).

intro.rs
📝 Edit Code
👁 Output
💡 Tip: keep a // Expected Output: line so the output panel has something to show.
🔍Line-by-line
LineMeaning
fn main() {Program entry point.
println!("Welcome to Rust");Print macro outputs text.
}Rust line.
🏢Real-world
  • 1Rust is used for performance-critical and reliability-focused software.
Common Mistakes
  • 1Fighting the borrow checker instead of learning ownership rules.
Best Practices
  • 1Model ownership clearly and keep functions small.
📖Summary & Practice
  • 1Edit the example and rerun to learn faster.
  • 2Prefer clarity first; optimize later.
💡Practice: answer the questions below, then modify the example to match your answers.
  • 1Change one value and predict the output.
  • 2Add one edge case and handle it.
  • 3Explain the rule in 1 sentence.
📈SEO

Keywords (topic intent):

Rust Systems Rust Intro
∙ Chapter 004

Rust Get Started

Learn Rust Get Started with a small example you can edit and run.

📝Syntax
cargo new my-app
cargo run
Example (Edit & Run)

Edit the Rust code below and click Run. The output panel shows the extracted Expected Output notes (or simple prints).

get-started.rs
📝 Edit Code
👁 Output
💡 Tip: keep a // Expected Output: line so the output panel has something to show.
🔍Line-by-line
LineMeaning
fn main() {Program entry point.
println!("Welcome to Rust");Print macro outputs text.
}Rust line.
🏢Real-world
  • 1Rust is used for performance-critical and reliability-focused software.
Common Mistakes
  • 1Fighting the borrow checker instead of learning ownership rules.
Best Practices
  • 1Model ownership clearly and keep functions small.
📖Summary & Practice
  • 1Edit the example and rerun to learn faster.
  • 2Prefer clarity first; optimize later.
💡Practice: answer the questions below, then modify the example to match your answers.
  • 1Change one value and predict the output.
  • 2Add one edge case and handle it.
  • 3Explain the rule in 1 sentence.
📈SEO

Keywords (topic intent):

Rust Systems Rust Get Started
Rust Basics
∙ Chapter 005

Rust Syntax

Learn Rust Syntax with a small example you can edit and run.

📝Syntax
fn main() {
  println!("Hello");
}
Example (Edit & Run)

Edit the Rust code below and click Run. The output panel shows the extracted Expected Output notes (or simple prints).

syntax.rs
📝 Edit Code
👁 Output
💡 Tip: keep a // Expected Output: line so the output panel has something to show.
🔍Line-by-line
LineMeaning
fn main() {Program entry point.
let score = 82;Declares a variable (mutable with let mut).
let result = if score >= 75 { "Pass" } else { "Fail" };Declares a variable (mutable with let mut).
println!("{}", result);Print macro outputs text.
}Rust line.
🏢Real-world
  • 1Rust is used for performance-critical and reliability-focused software.
Common Mistakes
  • 1Fighting the borrow checker instead of learning ownership rules.
Best Practices
  • 1Model ownership clearly and keep functions small.
📖Summary & Practice
  • 1Edit the example and rerun to learn faster.
  • 2Prefer clarity first; optimize later.
💡Practice: answer the questions below, then modify the example to match your answers.
  • 1Change one value and predict the output.
  • 2Add one edge case and handle it.
  • 3Explain the rule in 1 sentence.
📈SEO

Keywords (topic intent):

Rust Systems Rust Syntax
∙ Chapter 006

Rust Output

Learn Rust Output with a small example you can edit and run.

📝Syntax
println!("Hello");
print!("No newline");
Example (Edit & Run)

Edit the Rust code below and click Run. The output panel shows the extracted Expected Output notes (or simple prints).

output.rs
📝 Edit Code
👁 Output
💡 Tip: keep a // Expected Output: line so the output panel has something to show.
🔍Line-by-line
LineMeaning
fn main() {Program entry point.
print!("Hi");Print macro outputs text.
print!(" ");Print macro outputs text.
println!("Rust");Print macro outputs text.
}Rust line.
🏢Real-world
  • 1Rust is used for performance-critical and reliability-focused software.
Common Mistakes
  • 1Fighting the borrow checker instead of learning ownership rules.
Best Practices
  • 1Model ownership clearly and keep functions small.
📖Summary & Practice
  • 1Edit the example and rerun to learn faster.
  • 2Prefer clarity first; optimize later.
💡Practice: answer the questions below, then modify the example to match your answers.
  • 1Change one value and predict the output.
  • 2Add one edge case and handle it.
  • 3Explain the rule in 1 sentence.
📈SEO

Keywords (topic intent):

Rust Systems Rust Output
∙ Chapter 007

Rust Comments

Learn Rust Comments with a small example you can edit and run.

📝Syntax
// line comment
/* block comment */
Example (Edit & Run)

Edit the Rust code below and click Run. The output panel shows the extracted Expected Output notes (or simple prints).

comments.rs
📝 Edit Code
👁 Output
💡 Tip: keep a // Expected Output: line so the output panel has something to show.
🔍Line-by-line
LineMeaning
fn main() {Program entry point.
/* multi-line comment */Rust line.
println!("Comments don't change output");Print macro outputs text.
}Rust line.
🏢Real-world
  • 1Rust is used for performance-critical and reliability-focused software.
Common Mistakes
  • 1Fighting the borrow checker instead of learning ownership rules.
Best Practices
  • 1Model ownership clearly and keep functions small.
📖Summary & Practice
  • 1Edit the example and rerun to learn faster.
  • 2Prefer clarity first; optimize later.
💡Practice: answer the questions below, then modify the example to match your answers.
  • 1Change one value and predict the output.
  • 2Add one edge case and handle it.
  • 3Explain the rule in 1 sentence.
📈SEO

Keywords (topic intent):

Rust Systems Rust Comments
∙ Chapter 008

Rust Variables

Learn Rust Variables with a small example you can edit and run.

📝Syntax
let x = 7;
let mut y = 0;
y += 1;
Example (Edit & Run)

Edit the Rust code below and click Run. The output panel shows the extracted Expected Output notes (or simple prints).

variables.rs
📝 Edit Code
👁 Output
💡 Tip: keep a // Expected Output: line so the output panel has something to show.
🔍Line-by-line
LineMeaning
fn main() {Program entry point.
let name = "Mana";Declares a variable (mutable with let mut).
let mut level = 1;Declares a variable (mutable with let mut).
level += 1;Rust line.
println!("{} level {}", name, level);Print macro outputs text.
}Rust line.
🏢Real-world
  • 1Rust is used for performance-critical and reliability-focused software.
Common Mistakes
  • 1Fighting the borrow checker instead of learning ownership rules.
Best Practices
  • 1Model ownership clearly and keep functions small.
📖Summary & Practice
  • 1Edit the example and rerun to learn faster.
  • 2Prefer clarity first; optimize later.
💡Practice: answer the questions below, then modify the example to match your answers.
  • 1Change one value and predict the output.
  • 2Add one edge case and handle it.
  • 3Explain the rule in 1 sentence.
📈SEO

Keywords (topic intent):

Rust Systems Rust Variables
∙ Chapter 009

Rust Data Types

Learn Rust Data Types with a small example you can edit and run.

📝Syntax
let a: i32 = 7;
let b: f64 = 3.14;
let ok: bool = true;
Example (Edit & Run)

Edit the Rust code below and click Run. The output panel shows the extracted Expected Output notes (or simple prints).

data-types.rs
📝 Edit Code
👁 Output
💡 Tip: keep a // Expected Output: line so the output panel has something to show.
🔍Line-by-line
LineMeaning
fn main() {Program entry point.
let a: i32 = 10;Declares a variable (mutable with let mut).
let b: f64 = 3.5;Declares a variable (mutable with let mut).
let ok: bool = true;Declares a variable (mutable with let mut).
let c: char = 'A';Declares a variable (mutable with let mut).
println!("{} {} {} {}", a, b, ok, c);Print macro outputs text.
}Rust line.
🏢Real-world
  • 1Rust is used for performance-critical and reliability-focused software.
Common Mistakes
  • 1Fighting the borrow checker instead of learning ownership rules.
Best Practices
  • 1Model ownership clearly and keep functions small.
📖Summary & Practice
  • 1Edit the example and rerun to learn faster.
  • 2Prefer clarity first; optimize later.
💡Practice: answer the questions below, then modify the example to match your answers.
  • 1Change one value and predict the output.
  • 2Add one edge case and handle it.
  • 3Explain the rule in 1 sentence.
📈SEO

Keywords (topic intent):

Rust Systems Rust Data Types
∙ Chapter 010

Rust Constants

Learn Rust Constants with a small example you can edit and run.

📝Syntax
const MAX: i32 = 100;
Example (Edit & Run)

Edit the Rust code below and click Run. The output panel shows the extracted Expected Output notes (or simple prints).

constants.rs
📝 Edit Code
👁 Output
💡 Tip: keep a // Expected Output: line so the output panel has something to show.
🔍Line-by-line
LineMeaning
const MAX: i32 = 100;Declares a constant.
fn main() {Program entry point.
println!("{}", MAX);Print macro outputs text.
}Rust line.
🏢Real-world
  • 1Rust is used for performance-critical and reliability-focused software.
Common Mistakes
  • 1Fighting the borrow checker instead of learning ownership rules.
Best Practices
  • 1Model ownership clearly and keep functions small.
📖Summary & Practice
  • 1Edit the example and rerun to learn faster.
  • 2Prefer clarity first; optimize later.
💡Practice: answer the questions below, then modify the example to match your answers.
  • 1Change one value and predict the output.
  • 2Add one edge case and handle it.
  • 3Explain the rule in 1 sentence.
📈SEO

Keywords (topic intent):

Rust Systems Rust Constants
∙ Chapter 011

Rust Operators

Learn Rust Operators with a small example you can edit and run.

📝Syntax
let sum = a + b;
let gt = a > b;
let and = ok && other;
Example (Edit & Run)

Edit the Rust code below and click Run. The output panel shows the extracted Expected Output notes (or simple prints).

operators.rs
📝 Edit Code
👁 Output
💡 Tip: keep a // Expected Output: line so the output panel has something to show.
🔍Line-by-line
LineMeaning
fn main() {Program entry point.
let a = 7;Declares a variable (mutable with let mut).
let b = 3;Declares a variable (mutable with let mut).
println!("{}", a + b);Print macro outputs text.
}Rust line.
🏢Real-world
  • 1Rust is used for performance-critical and reliability-focused software.
Common Mistakes
  • 1Fighting the borrow checker instead of learning ownership rules.
Best Practices
  • 1Model ownership clearly and keep functions small.
📖Summary & Practice
  • 1Edit the example and rerun to learn faster.
  • 2Prefer clarity first; optimize later.
💡Practice: answer the questions below, then modify the example to match your answers.
  • 1Change one value and predict the output.
  • 2Add one edge case and handle it.
  • 3Explain the rule in 1 sentence.
📈SEO

Keywords (topic intent):

Rust Systems Rust Operators
∙ Chapter 012

Rust Booleans

Learn Rust Booleans with a small example you can edit and run.

📝Syntax
let ok = (a >= 10) && (b < 5);
Example (Edit & Run)

Edit the Rust code below and click Run. The output panel shows the extracted Expected Output notes (or simple prints).

booleans.rs
📝 Edit Code
👁 Output
💡 Tip: keep a // Expected Output: line so the output panel has something to show.
🔍Line-by-line
LineMeaning
fn main() {Program entry point.
let a = 10;Declares a variable (mutable with let mut).
let b = 2;Declares a variable (mutable with let mut).
let ok = (a >= 10) && (b < 5);Declares a variable (mutable with let mut).
println!("{}", ok);Print macro outputs text.
}Rust line.
🏢Real-world
  • 1Rust is used for performance-critical and reliability-focused software.
Common Mistakes
  • 1Fighting the borrow checker instead of learning ownership rules.
Best Practices
  • 1Model ownership clearly and keep functions small.
📖Summary & Practice
  • 1Edit the example and rerun to learn faster.
  • 2Prefer clarity first; optimize later.
💡Practice: answer the questions below, then modify the example to match your answers.
  • 1Change one value and predict the output.
  • 2Add one edge case and handle it.
  • 3Explain the rule in 1 sentence.
📈SEO

Keywords (topic intent):

Rust Systems Rust Booleans
∙ Chapter 013

Rust Strings

Learn Rust Strings with a small example you can edit and run.

📝Syntax
let s = String::from("hi");
let t = &s;
Example (Edit & Run)

Edit the Rust code below and click Run. The output panel shows the extracted Expected Output notes (or simple prints).

strings.rs
📝 Edit Code
👁 Output
💡 Tip: keep a // Expected Output: line so the output panel has something to show.
🔍Line-by-line
LineMeaning
fn main() {Program entry point.
let mut s = String::from("Mana");Declares a variable (mutable with let mut).
s.push_str(" Coding");Rust line.
println!("{}", s);Print macro outputs text.
}Rust line.
🏢Real-world
  • 1Ownership rules help prevent use-after-free and data races at compile time.
Common Mistakes
  • 1Cloning too much to “make errors go away”.
Best Practices
  • 1Borrow when you can, clone when you must.
📖Summary & Practice
  • 1Edit the example and rerun to learn faster.
  • 2Prefer clarity first; optimize later.
💡Practice: answer the questions below, then modify the example to match your answers.
  • 1Change one value and predict the output.
  • 2Add one edge case and handle it.
  • 3Explain the rule in 1 sentence.
📈SEO

Keywords (topic intent):

Rust Systems Rust Strings
Rust Control Flow
∙ Chapter 014

Rust If..Else

Learn Rust If..Else with a small example you can edit and run.

📝Syntax
let label = if score >= 75 { "Pass" } else { "Fail" };
Example (Edit & Run)

Edit the Rust code below and click Run. The output panel shows the extracted Expected Output notes (or simple prints).

if-else.rs
📝 Edit Code
👁 Output
💡 Tip: keep a // Expected Output: line so the output panel has something to show.
🔍Line-by-line
LineMeaning
fn main() {Program entry point.
let score = 75;Declares a variable (mutable with let mut).
if score >= 90 { println!("A"); }Print macro outputs text.
else if score >= 75 { println!("B"); }Print macro outputs text.
else { println!("C"); }Print macro outputs text.
}Rust line.
🏢Real-world
  • 1Control flow powers validation, parsers, and state machines.
Common Mistakes
  • 1Ignoring the wildcard arm in match or missing edge cases.
Best Practices
  • 1Use match for exhaustive handling and test boundaries.
📖Summary & Practice
  • 1Edit the example and rerun to learn faster.
  • 2Prefer clarity first; optimize later.
💡Practice: answer the questions below, then modify the example to match your answers.
  • 1Change one value and predict the output.
  • 2Add one edge case and handle it.
  • 3Explain the rule in 1 sentence.
📈SEO

Keywords (topic intent):

Rust Systems Rust If..Else
∙ Chapter 015

Rust Match

Learn Rust Match with a small example you can edit and run.

📝Syntax
match x {
  0 => "zero",
  _ => "other",
}
Example (Edit & Run)

Edit the Rust code below and click Run. The output panel shows the extracted Expected Output notes (or simple prints).

match.rs
📝 Edit Code
👁 Output
💡 Tip: keep a // Expected Output: line so the output panel has something to show.
🔍Line-by-line
LineMeaning
fn main() {Program entry point.
let day = 3;Declares a variable (mutable with let mut).
let name = match day {Declares a variable (mutable with let mut).
1 => "Mon",Rust line.
2 => "Tue",Rust line.
3 => "Wed",Rust line.
_ => "Other",Rust line.
};Rust line.
println!("{}", name);Print macro outputs text.
}Rust line.
🏢Real-world
  • 1Control flow powers validation, parsers, and state machines.
Common Mistakes
  • 1Ignoring the wildcard arm in match or missing edge cases.
Best Practices
  • 1Use match for exhaustive handling and test boundaries.
📖Summary & Practice
  • 1Edit the example and rerun to learn faster.
  • 2Prefer clarity first; optimize later.
💡Practice: answer the questions below, then modify the example to match your answers.
  • 1Change one value and predict the output.
  • 2Add one edge case and handle it.
  • 3Explain the rule in 1 sentence.
📈SEO

Keywords (topic intent):

Rust Systems Rust Match
∙ Chapter 016

Rust Loops

Learn Rust Loops with a small example you can edit and run.

📝Syntax
loop { break; }
Example (Edit & Run)

Edit the Rust code below and click Run. The output panel shows the extracted Expected Output notes (or simple prints).

loops.rs
📝 Edit Code
👁 Output
💡 Tip: keep a // Expected Output: line so the output panel has something to show.
🔍Line-by-line
LineMeaning
fn main() {Program entry point.
let mut i = 0;Declares a variable (mutable with let mut).
loop {Infinite loop (use break to exit).
i += 1;Rust line.
if i == 3 { break; }Conditional branch.
}Rust line.
println!("{}", i);Print macro outputs text.
}Rust line.
🏢Real-world
  • 1Control flow powers validation, parsers, and state machines.
Common Mistakes
  • 1Ignoring the wildcard arm in match or missing edge cases.
Best Practices
  • 1Use match for exhaustive handling and test boundaries.
📖Summary & Practice
  • 1Edit the example and rerun to learn faster.
  • 2Prefer clarity first; optimize later.
💡Practice: answer the questions below, then modify the example to match your answers.
  • 1Change one value and predict the output.
  • 2Add one edge case and handle it.
  • 3Explain the rule in 1 sentence.
📈SEO

Keywords (topic intent):

Rust Systems Rust Loops
∙ Chapter 017

Rust While Loops

Learn Rust While Loops with a small example you can edit and run.

📝Syntax
while i < 5 { i += 1; }
Example (Edit & Run)

Edit the Rust code below and click Run. The output panel shows the extracted Expected Output notes (or simple prints).

while-loops.rs
📝 Edit Code
👁 Output
💡 Tip: keep a // Expected Output: line so the output panel has something to show.
🔍Line-by-line
LineMeaning
fn main() {Program entry point.
let mut n = 1;Declares a variable (mutable with let mut).
let mut sum = 0;Declares a variable (mutable with let mut).
while n <= 5 {Loop while condition is true.
sum += n;Rust line.
n += 1;Rust line.
}Rust line.
println!("{}", sum);Print macro outputs text.
}Rust line.
🏢Real-world
  • 1Control flow powers validation, parsers, and state machines.
Common Mistakes
  • 1Ignoring the wildcard arm in match or missing edge cases.
Best Practices
  • 1Use match for exhaustive handling and test boundaries.
📖Summary & Practice
  • 1Edit the example and rerun to learn faster.
  • 2Prefer clarity first; optimize later.
💡Practice: answer the questions below, then modify the example to match your answers.
  • 1Change one value and predict the output.
  • 2Add one edge case and handle it.
  • 3Explain the rule in 1 sentence.
📈SEO

Keywords (topic intent):

Rust Systems Rust While Loops
∙ Chapter 018

Rust For Loops

Learn Rust For Loops with a small example you can edit and run.

📝Syntax
for i in 1..=3 { println!("{}", i); }
Example (Edit & Run)

Edit the Rust code below and click Run. The output panel shows the extracted Expected Output notes (or simple prints).

for-loops.rs
📝 Edit Code
👁 Output
💡 Tip: keep a // Expected Output: line so the output panel has something to show.
🔍Line-by-line
LineMeaning
fn main() {Program entry point.
for i in 1..=3 {Loop over an iterator/range.
print!("i={} ", i);Print macro outputs text.
}Rust line.
}Rust line.
🏢Real-world
  • 1Control flow powers validation, parsers, and state machines.
Common Mistakes
  • 1Ignoring the wildcard arm in match or missing edge cases.
Best Practices
  • 1Use match for exhaustive handling and test boundaries.
📖Summary & Practice
  • 1Edit the example and rerun to learn faster.
  • 2Prefer clarity first; optimize later.
💡Practice: answer the questions below, then modify the example to match your answers.
  • 1Change one value and predict the output.
  • 2Add one edge case and handle it.
  • 3Explain the rule in 1 sentence.
📈SEO

Keywords (topic intent):

Rust Systems Rust For Loops
∙ Chapter 019

Rust Functions

Learn Rust Functions with a small example you can edit and run.

📝Syntax
fn add(a: i32, b: i32) -> i32 { a + b }
Example (Edit & Run)

Edit the Rust code below and click Run. The output panel shows the extracted Expected Output notes (or simple prints).

functions.rs
📝 Edit Code
👁 Output
💡 Tip: keep a // Expected Output: line so the output panel has something to show.
🔍Line-by-line
LineMeaning
fn add(a: i32, b: i32) -> i32 { a + b }Declares a function.
fn main() {Program entry point.
println!("{}", add(4, 6));Print macro outputs text.
}Rust line.
🏢Real-world
  • 1Rust is used for performance-critical and reliability-focused software.
Common Mistakes
  • 1Fighting the borrow checker instead of learning ownership rules.
Best Practices
  • 1Model ownership clearly and keep functions small.
📖Summary & Practice
  • 1Edit the example and rerun to learn faster.
  • 2Prefer clarity first; optimize later.
💡Practice: answer the questions below, then modify the example to match your answers.
  • 1Change one value and predict the output.
  • 2Add one edge case and handle it.
  • 3Explain the rule in 1 sentence.
📈SEO

Keywords (topic intent):

Rust Systems Rust Functions
∙ Chapter 020

Rust Scope

Learn Rust Scope with a small example you can edit and run.

📝Syntax
{ let x = 1; }
// x not available here
Example (Edit & Run)

Edit the Rust code below and click Run. The output panel shows the extracted Expected Output notes (or simple prints).

scope.rs
📝 Edit Code
👁 Output
💡 Tip: keep a // Expected Output: line so the output panel has something to show.
🔍Line-by-line
LineMeaning
fn main() {Program entry point.
let x = 1;Declares a variable (mutable with let mut).
{Rust line.
let x = 2;Declares a variable (mutable with let mut).
println!("{}", x);Print macro outputs text.
}Rust line.
println!("{}", x);Print macro outputs text.
}Rust line.
🏢Real-world
  • 1Rust is used for performance-critical and reliability-focused software.
Common Mistakes
  • 1Fighting the borrow checker instead of learning ownership rules.
Best Practices
  • 1Model ownership clearly and keep functions small.
📖Summary & Practice
  • 1Edit the example and rerun to learn faster.
  • 2Prefer clarity first; optimize later.
💡Practice: answer the questions below, then modify the example to match your answers.
  • 1Change one value and predict the output.
  • 2Add one edge case and handle it.
  • 3Explain the rule in 1 sentence.
📈SEO

Keywords (topic intent):

Rust Systems Rust Scope
Rust Ownership
∙ Chapter 021

Rust Ownership

Learn Rust Ownership with a small example you can edit and run.

📝Syntax
let s = String::from("hi");
// s moved
Example (Edit & Run)

Edit the Rust code below and click Run. The output panel shows the extracted Expected Output notes (or simple prints).

ownership.rs
📝 Edit Code
👁 Output
💡 Tip: keep a // Expected Output: line so the output panel has something to show.
🔍Line-by-line
LineMeaning
fn main() {Program entry point.
let s1 = String::from("hello");Declares a variable (mutable with let mut).
let s2 = s1;Declares a variable (mutable with let mut).
println!("{}", s2);Print macro outputs text.
}Rust line.
🏢Real-world
  • 1Ownership rules help prevent use-after-free and data races at compile time.
Common Mistakes
  • 1Cloning too much to “make errors go away”.
Best Practices
  • 1Borrow when you can, clone when you must.
📖Summary & Practice
  • 1Edit the example and rerun to learn faster.
  • 2Prefer clarity first; optimize later.
💡Practice: answer the questions below, then modify the example to match your answers.
  • 1Change one value and predict the output.
  • 2Add one edge case and handle it.
  • 3Explain the rule in 1 sentence.
📈SEO

Keywords (topic intent):

Rust Systems Rust Ownership
∙ Chapter 022

Rust Borrowing

Learn Rust Borrowing with a small example you can edit and run.

📝Syntax
fn len(s: &String) -> usize { s.len() }
Example (Edit & Run)

Edit the Rust code below and click Run. The output panel shows the extracted Expected Output notes (or simple prints).

borrowing.rs
📝 Edit Code
👁 Output
💡 Tip: keep a // Expected Output: line so the output panel has something to show.
🔍Line-by-line
LineMeaning
fn len(s: &String) -> usize { s.len() }Declares a function.
fn main() {Program entry point.
let s = String::from("Mana");Declares a variable (mutable with let mut).
println!("{}", len(&s));Print macro outputs text.
println!("{}", s);Print macro outputs text.
}Rust line.
🏢Real-world
  • 1Ownership rules help prevent use-after-free and data races at compile time.
Common Mistakes
  • 1Cloning too much to “make errors go away”.
Best Practices
  • 1Borrow when you can, clone when you must.
📖Summary & Practice
  • 1Edit the example and rerun to learn faster.
  • 2Prefer clarity first; optimize later.
💡Practice: answer the questions below, then modify the example to match your answers.
  • 1Change one value and predict the output.
  • 2Add one edge case and handle it.
  • 3Explain the rule in 1 sentence.
📈SEO

Keywords (topic intent):

Rust Systems Rust Borrowing
Rust Data Structures
∙ Chapter 023

Rust Data Structures

Learn Rust Data Structures with a small example you can edit and run.

📝Syntax
Arrays, Vec<T>, tuples, HashMap<K,V>, structs, enums
Example (Edit & Run)

Edit the Rust code below and click Run. The output panel shows the extracted Expected Output notes (or simple prints).

data-structures.rs
📝 Edit Code
👁 Output
💡 Tip: keep a // Expected Output: line so the output panel has something to show.
🔍Line-by-line
LineMeaning
fn main() {Program entry point.
println!("Arrays, Vec, tuples, HashMap, structs, enums");Print macro outputs text.
}Rust line.
🏢Real-world
  • 1Data structures model your domain and impact performance and readability.
Common Mistakes
  • 1Picking the wrong collection type for the job.
Best Practices
  • 1Start simple (Vec/struct), then optimize with profiling.
📖Summary & Practice
  • 1Edit the example and rerun to learn faster.
  • 2Prefer clarity first; optimize later.
💡Practice: answer the questions below, then modify the example to match your answers.
  • 1Change one value and predict the output.
  • 2Add one edge case and handle it.
  • 3Explain the rule in 1 sentence.
📈SEO

Keywords (topic intent):

Rust Systems Rust Data Structures
∙ Chapter 024

Rust Arrays

Learn Rust Arrays with a small example you can edit and run.

📝Syntax
let a = [1, 2, 3];
Example (Edit & Run)

Edit the Rust code below and click Run. The output panel shows the extracted Expected Output notes (or simple prints).

arrays.rs
📝 Edit Code
👁 Output
💡 Tip: keep a // Expected Output: line so the output panel has something to show.
🔍Line-by-line
LineMeaning
fn main() {Program entry point.
let nums = [1, 2, 3, 4];Declares a variable (mutable with let mut).
let mut sum = 0;Declares a variable (mutable with let mut).
for x in nums { sum += x; }Loop over an iterator/range.
println!("{}", sum);Print macro outputs text.
}Rust line.
🏢Real-world
  • 1Data structures model your domain and impact performance and readability.
Common Mistakes
  • 1Picking the wrong collection type for the job.
Best Practices
  • 1Start simple (Vec/struct), then optimize with profiling.
📖Summary & Practice
  • 1Edit the example and rerun to learn faster.
  • 2Prefer clarity first; optimize later.
💡Practice: answer the questions below, then modify the example to match your answers.
  • 1Change one value and predict the output.
  • 2Add one edge case and handle it.
  • 3Explain the rule in 1 sentence.
📈SEO

Keywords (topic intent):

Rust Systems Rust Arrays
∙ Chapter 025

Rust Vectors

Learn Rust Vectors with a small example you can edit and run.

📝Syntax
let v = vec![1, 2, 3];
Example (Edit & Run)

Edit the Rust code below and click Run. The output panel shows the extracted Expected Output notes (or simple prints).

vectors.rs
📝 Edit Code
👁 Output
💡 Tip: keep a // Expected Output: line so the output panel has something to show.
🔍Line-by-line
LineMeaning
fn main() {Program entry point.
let mut v = vec![1, 2, 3];Declares a variable (mutable with let mut).
v.push(4);Rust line.
let sum: i32 = v.iter().sum();Declares a variable (mutable with let mut).
println!("{}", sum);Print macro outputs text.
}Rust line.
🏢Real-world
  • 1Data structures model your domain and impact performance and readability.
Common Mistakes
  • 1Picking the wrong collection type for the job.
Best Practices
  • 1Start simple (Vec/struct), then optimize with profiling.
📖Summary & Practice
  • 1Edit the example and rerun to learn faster.
  • 2Prefer clarity first; optimize later.
💡Practice: answer the questions below, then modify the example to match your answers.
  • 1Change one value and predict the output.
  • 2Add one edge case and handle it.
  • 3Explain the rule in 1 sentence.
📈SEO

Keywords (topic intent):

Rust Systems Rust Vectors
∙ Chapter 026

Rust Tuples

Learn Rust Tuples with a small example you can edit and run.

📝Syntax
let t = (1, "a");
Example (Edit & Run)

Edit the Rust code below and click Run. The output panel shows the extracted Expected Output notes (or simple prints).

tuples.rs
📝 Edit Code
👁 Output
💡 Tip: keep a // Expected Output: line so the output panel has something to show.
🔍Line-by-line
LineMeaning
fn main() {Program entry point.
let t = (7, "hi");Declares a variable (mutable with let mut).
println!("{} {}", t.0, t.1);Print macro outputs text.
}Rust line.
🏢Real-world
  • 1Data structures model your domain and impact performance and readability.
Common Mistakes
  • 1Picking the wrong collection type for the job.
Best Practices
  • 1Start simple (Vec/struct), then optimize with profiling.
📖Summary & Practice
  • 1Edit the example and rerun to learn faster.
  • 2Prefer clarity first; optimize later.
💡Practice: answer the questions below, then modify the example to match your answers.
  • 1Change one value and predict the output.
  • 2Add one edge case and handle it.
  • 3Explain the rule in 1 sentence.
📈SEO

Keywords (topic intent):

Rust Systems Rust Tuples
∙ Chapter 027

Rust HashMap

Learn Rust HashMap with a small example you can edit and run.

📝Syntax
use std::collections::HashMap;
let mut m = HashMap::new();
Example (Edit & Run)

Edit the Rust code below and click Run. The output panel shows the extracted Expected Output notes (or simple prints).

hashmap.rs
📝 Edit Code
👁 Output
💡 Tip: keep a // Expected Output: line so the output panel has something to show.
🔍Line-by-line
LineMeaning
use std::collections::HashMap;Rust line.
fn main() {Program entry point.
let mut m = HashMap::new();Declares a variable (mutable with let mut).
m.insert("SQL", 2);Rust line.
println!("{}", m["SQL"]);Print macro outputs text.
}Rust line.
🏢Real-world
  • 1Data structures model your domain and impact performance and readability.
Common Mistakes
  • 1Picking the wrong collection type for the job.
Best Practices
  • 1Start simple (Vec/struct), then optimize with profiling.
📖Summary & Practice
  • 1Edit the example and rerun to learn faster.
  • 2Prefer clarity first; optimize later.
💡Practice: answer the questions below, then modify the example to match your answers.
  • 1Change one value and predict the output.
  • 2Add one edge case and handle it.
  • 3Explain the rule in 1 sentence.
📈SEO

Keywords (topic intent):

Rust Systems Rust HashMap
∙ Chapter 028

Rust Structs

Learn Rust Structs with a small example you can edit and run.

📝Syntax
struct User { name: String }
Example (Edit & Run)

Edit the Rust code below and click Run. The output panel shows the extracted Expected Output notes (or simple prints).

structs.rs
📝 Edit Code
👁 Output
💡 Tip: keep a // Expected Output: line so the output panel has something to show.
🔍Line-by-line
LineMeaning
struct User { name: String }Rust line.
fn main() {Program entry point.
let u = User { name: String::from("Mana") };Declares a variable (mutable with let mut).
println!("{}", u.name);Print macro outputs text.
}Rust line.
🏢Real-world
  • 1Data structures model your domain and impact performance and readability.
Common Mistakes
  • 1Picking the wrong collection type for the job.
Best Practices
  • 1Start simple (Vec/struct), then optimize with profiling.
📖Summary & Practice
  • 1Edit the example and rerun to learn faster.
  • 2Prefer clarity first; optimize later.
💡Practice: answer the questions below, then modify the example to match your answers.
  • 1Change one value and predict the output.
  • 2Add one edge case and handle it.
  • 3Explain the rule in 1 sentence.
📈SEO

Keywords (topic intent):

Rust Systems Rust Structs
∙ Chapter 029

Rust Enums

Learn Rust Enums with a small example you can edit and run.

📝Syntax
enum Status { Active, Inactive }
Example (Edit & Run)

Edit the Rust code below and click Run. The output panel shows the extracted Expected Output notes (or simple prints).

enums.rs
📝 Edit Code
👁 Output
💡 Tip: keep a // Expected Output: line so the output panel has something to show.
🔍Line-by-line
LineMeaning
enum Status { Active, Inactive }Rust line.
fn main() {Program entry point.
let s = Status::Active;Declares a variable (mutable with let mut).
match s {Pattern matching with match.
Status::Active => println!("Active"),Print macro outputs text.
Status::Inactive => println!("Inactive"),Print macro outputs text.
}Rust line.
}Rust line.
🏢Real-world
  • 1Data structures model your domain and impact performance and readability.
Common Mistakes
  • 1Picking the wrong collection type for the job.
Best Practices
  • 1Start simple (Vec/struct), then optimize with profiling.
📖Summary & Practice
  • 1Edit the example and rerun to learn faster.
  • 2Prefer clarity first; optimize later.
💡Practice: answer the questions below, then modify the example to match your answers.
  • 1Change one value and predict the output.
  • 2Add one edge case and handle it.
  • 3Explain the rule in 1 sentence.
📈SEO

Keywords (topic intent):

Rust Systems Rust Enums
PreviousBack to Home
🎉 Rust Tutorial Complete (29 topics)!
Next UpKotlin Basics →