Vibe Engines
YouTube

Vibe Engines is free, interactive AI engineering & system design — runs in your browser. Pick a learning path

Learn RustChapter 1: Hello

Lesson 1.7 · 8 min

Chapter review: Hello

Chapter 1 took you from "what is a program?" to a Chatterbox with a banner and a greeting, each in a function of its own. Before the program starts remembering things, check that the whole chapter has stuck: a mixed quiz, then one bigger exercise that uses all of it at once.

Adds to ChatterboxNothing new: a mixed quiz on the whole chapter, and a bigger exercise that uses all of it.

What chapter 1 gave you

Chatterbox v0.1 is small, but it is a real program you made and ran: it prints a banner and greets Sam by name, and both lines come from functions you wrote. Here is the chapter in one line per lesson. If a line feels shaky, the link takes you back.

  • 1.1 What a program is: a list of steps the computer follows exactly, in order, starting at main. The compiler turns your text into a program first; running it comes second.
  • 1.2 Make and run a project: cargo new makes the folder, cargo run builds and runs it, cargo check only asks "does this make sense?".
  • 1.3 Printing and comments: println! fills each {} hole with the next value after the comma, format! builds the same text without printing it, and the compiler skips everything after //.
  • 1.4 Chatterbox says hello: those pieces put together into the first real version of Chatterbox.
  • 1.5 Reading what the compiler says: headline for what, arrow for where, underline for which characters, help line for what to try. E0425 is a name nothing defines; E0308 is a value of the wrong type.
  • 1.6 Functions: a named list of steps with inputs (parameters) and an output (the type after the arrow). The last line with no semicolon is the answer it hands back, and a call with the wrong number of inputs is E0061.

Mixed quiz

Seven short programs, all new, and the ideas are shuffled on purpose: a printing question, then an error, then a function. Mixing them is harder than answering seven of the same kind in a row, and that difficulty is what makes it stick. For each one, decide before you pick: does it compile? If it does, what exactly does it print? Every answer below was produced by the real compiler.

PredictA banner with a note
fn main() {
// println!("Chatterbox v0.0");
println!("{} v{}", "Chatterbox", "0.1"); // the banner
}

What does this print?

  • Chatterbox v0.1
  • Chatterbox v0.0
  • Chatterbox v0.1 // the banner
Reveal the answer

The program prints: Chatterbox v0.1 The first line inside main starts with //, so the whole line is a comment and the compiler never sees that old banner. On the next line, everything after // is a comment too, so the banner is a note for people, not text to print. Revisit lesson 1.3 if either surprised you.

PredictA banner that wants two inputs
fn banner(bot: &str, version: &str) -> String {
format!("{} v{}", bot, version)
}
 
fn main() {
println!("{}", banner("Chatterbox"));
}

Does this compile — and if it does, does it run?

  • It compiles and runs
  • Compile error E0061
  • Compile error E0425
Reveal the answer

It does not compile: E0061. banner promises two parameters, a bot and a version, and the call gives it one. A call has to match the function's first line exactly, one argument per parameter, so the compiler stops with E0061 and says which argument is missing. That contract is lesson 1.6.

error[E0061]: this function takes 2 arguments but 1 argument was supplied
 --> src/main.rs:6:20
  |
6 |     println!("{}", banner("Chatterbox"));
  |                    ^^^^^^-------------- argument #2 of type `&str` is missing
  |
note: function defined here
 --> src/main.rs:1:4
  |
1 | fn banner(bot: &str, version: &str) -> String {
  |    ^^^^^^            -------------
help: provide the argument
  |
6 |     println!("{}", banner("Chatterbox", /* &str */));
  |                                       ++++++++++++
PredictHoles that do sums
fn main() {
println!("{} sent {} messages and {} words", "Sam", 1 + 2, 3 * 4);
}

What does this print?

  • Sam sent 3 messages and 12 words
  • Sam sent 1 + 2 messages and 3 * 4 words
  • {} sent {} messages and {} words
Reveal the answer

The program prints: Sam sent 3 messages and 12 words The holes are filled left to right with the values after the comma. 1 + 2 and 3 * 4 are not text, they are sums, so Rust works each one out first and prints the result. Only what is inside the quotes is printed as it is written (lesson 1.3).

PredictA greeting with a slip
fn greeting(name: &str) -> String {
format!("Hi {}! I'm Chatterbox.", nmae)
}
 
fn main() {
println!("{}", greeting("Sam"));
}

Does this compile — and if it does, does it run?

  • It compiles and runs
  • Compile error E0425
  • Compile error E0061
Reveal the answer

It does not compile: E0425. The parameter is called name, but the body asks for nmae. The compiler matches names letter by letter and nothing in the program is called nmae, so it stops with E0425, "cannot find value". The help line even suggests the parameter it probably meant. Lesson 1.5 takes this message apart.

error[E0425]: cannot find value `nmae` in this scope
 --> src/main.rs:2:39
  |
2 |     format!("Hi {}! I'm Chatterbox.", nmae)
  |                                       ^^^^
  |
help: a local variable with a similar name exists
  |
2 -     format!("Hi {}! I'm Chatterbox.", nmae)
2 +     format!("Hi {}! I'm Chatterbox.", name)
  |
PredictWritten in one order, called in another
fn footer() -> String {
format!("{} messages today", 2)
}
 
fn banner() -> String {
format!("{} v{}", "Chatterbox", "0.1")
}
 
fn main() {
println!("{}", banner());
println!("{}", footer());
}

footer is written first in the file. What is the first line this program prints?

  • 2 messages today
  • Chatterbox v0.1
  • footer
Reveal the answer

The program prints: Chatterbox v0.1 Defining a function only writes the recipe down; nothing runs until it is called. The program starts in main, and main calls banner() first, so the banner is the first line, wherever the functions sit in the file. Lessons 1.1 and 1.6 both lean on this.

PredictA banner that prints instead of handing back
fn banner() -> String {
println!("Chatterbox v0.1")
}
 
fn main() {
println!("{}", banner());
}

Does this compile — and if it does, does it run?

  • It compiles and runs
  • Compile error E0308
  • Compile error E0061
Reveal the answer

It does not compile: E0308. The last line has no semicolon, so its value is what banner hands back. But println! puts text on the screen and produces nothing, written (), while the arrow promised a String. Expected String, found (): E0308. Building the text with format! is what fits that promise (lessons 1.5 and 1.6).

error[E0308]: mismatched types
 --> src/main.rs:2:5
  |
2 |     println!("Chatterbox v0.1")
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `String`, found `()`
PredictFunctions below main, calling each other
fn main() {
println!("{}", welcome("Ada"));
}
 
fn welcome(name: &str) -> String {
format!("{} | Hi {}!", banner(), name)
}
 
fn banner() -> String {
String::from("Chatterbox v0.1")
}

Does this compile — and if it does, does it run?

  • It compiles and runs
  • Compile error E0425
  • Compile error E0061
Reveal the answer

It compiles and runs. It compiles and prints Chatterbox v0.1 | Hi Ada!. The compiler reads the whole file before it complains about a name, so functions written below main are found. And a call like banner() is an expression, so it can fill a hole inside another function's format!. Revisit lesson 1.6 if you expected E0425.

Milestone: the opening line

Now everything at once. Chatterbox's opening becomes one line built from three functions: banner makes the name and version, greeting says hi to one person, and opening joins the two. Read each function's first line and the comment above it carefully: together they are the whole specification. The hidden tests try more than one bot name and more than one person, so nothing can be typed in where a parameter belongs.

Try itYour turn: three functions, one opening line

Write the three bodies. banner("Chatterbox", "0.1") gives Chatterbox v0.1. greeting("Sam", "Chatterbox") gives Hi Sam! I'm Chatterbox.. opening("Sam") gives Chatterbox's banner at version 0.1, then | , then Chatterbox's greeting to Sam: Chatterbox v0.1 | Hi Sam! I'm Chatterbox.. Each todo!() is a placeholder that compiles but stops the program if it is reached; replace it.

Write the three bodies. banner("Chatterbox", "0.1") gives Chatterbox v0.1. greeting("Sam", "Chatterbox") gives Hi Sam! I'm Chatterbox.. opening("Sam") gives Chatterbox's banner at version 0.1, then | , then Chatterbox's greeting to Sam: Chatterbox v0.1 | Hi Sam! I'm Chatterbox.. Each todo!() is a placeholder that compiles but stops the program if it is reached; replace it.

// Chatterbox's opening line, built from three small functions.
 
/// The first line: a bot's name and version, like "Chatterbox v0.1".
fn banner(bot: &str, version: &str) -> String {
todo!()
}
 
/// A hello from a bot to one person, like "Hi Sam! I'm Chatterbox."
fn greeting(name: &str, bot: &str) -> String {
todo!()
}
 
/// The whole opening on one line: Chatterbox's banner at version 0.1,
/// then " | ", then Chatterbox's greeting to name. Use the two functions above.
fn opening(name: &str) -> String {
todo!()
}
 
fn main() {
println!("{}", opening("Sam"));
}

Hidden tests (7): banner_for_any_bot banner_for_chatterbox greeting_for_sam greeting_uses_both_inputs opening_for_anyone opening_with_an_empty_name opening_for_sam

This exercise runs real Rust in your browser through the official Rust Playground, so it needs JavaScript.

Where this leaves you

If the quiz went well and the tests are green, you have the whole of chapter 1: you can read a short program and say what it will do, read the compiler's message when it will not, and split a job into functions that hand answers to each other. Notice how often the exercise typed "Chatterbox": four times, in two different functions. Chapter 2 starts by giving values names, so a fact like that is written once.

Self-check

Say it out loud, then reveal

Self-checkRetrieval beats re-reading
Say, in order, the four places you look when the compiler prints an error.Reveal
The headline for what went wrong, the arrow line for the file, line and column, the caret underline for the exact characters, then any help line for a suggested fix.
You see E0425, E0308 and E0061. What does each one say in plain words?Reveal
E0425: you used a name that nothing defines. E0308: a value is a different type from the one the code expects. E0061: a call gave a function the wrong number of arguments.
What is the difference between <code>println!</code> and <code>format!</code>, and which one belongs on the last line of a function that returns a <code>String</code>?Reveal
println! prints and produces nothing; format! builds the same text and hands it back. The last line of a function that returns a String needs format!, with no semicolon.
Why can <code>opening</code> use <code>banner(…)</code> inside its own <code>format!</code>?Reveal
A function call is an expression: it produces a value, so it can fill a hole just like quoted text or a sum.
Your Chatterbox so far: v0.1 (after lesson 1.6)
Chatterbox v0.1 after lesson 1.6: the whole program
src/main.rs
// Chatterbox: a small chat program, built one lesson at a time.
 
/// The first line Chatterbox prints.
fn banner() -> String {
format!("{} v{}", "Chatterbox", "0.1")
}
 
/// The greeting, with a name filled in.
fn greeting(name: &str) -> String {
format!("Hi {}! I'm {}.", name, "Chatterbox")
}
 
fn main() {
println!("{}", banner());
println!("{}", greeting("Sam"));
println!("Type a message and I will answer.");
}

Download this version (zip)Unzip, then cargo run inside the folder.

That is lesson 1.7. Tick it off so the course remembers where you are. That is also the end of chapter 1: a few minutes with the course flashcards now makes it stick, and the chapter’s cheat sheet has every idea on one screen.

Next: 2.1 Names for values →

Questions people ask

What should I know after the first chapter of Rust?

How to make and run a project with cargo, how to print text with holes and leave comments, how to read a compiler error and fix E0425, E0308 and E0061, and how to write functions with parameters and a return value.

Why does this course mix quiz questions instead of grouping them by topic?

Answering a mix forces you to decide which idea a question is about before you answer it, which is the skill you need when reading real code. It feels harder than a block of the same kind, and it is remembered better.

I got some quiz answers wrong. Should I go on to chapter 2?

Read the explanation under each wrong answer and revisit the lesson it names. If the milestone exercise passes its tests, you are ready; chapter 2 uses functions and format! on every page.

Can a Rust function call another function?

Yes. A call is an expression that produces a value, so it can appear anywhere a value can, including inside another function and inside a format! hole. The order the functions are written in the file does not matter.

Learn Rust by building a chat app · Lesson 1.7 · every compiler message above is real output from rustc 1.99.0 (b940084d7 2026-09-28) (edition 2024) · Vibe Engines · 2026