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.4 · 6 min

Chatterbox says hello

Time to add the first real piece to Chatterbox: a greeting that uses your name. Small, but it is a complete program, and it is the base every later lesson builds on.

Adds to ChatterboxA greeting that fills in your name.

Chatterbox v0.1

Put the last two lessons together. The program prints its banner, then a greeting that uses a name. Right now the name is typed straight into the code. In chapter 2 you will give it a proper name, and chapter 3 makes Chatterbox read what you type. For now we are only checking that the whole path works: text goes in, the compiler agrees, and a friendly line comes out.

Here is the whole program. The green lines are what this lesson changed.

Chatterbox v0.1 after lesson 1.4: the whole program (green lines are new in this lesson)
src/main.rs3 new lines
// Chatterbox: a small chat program, built one lesson at a time.
fn main() {
// The banner says who we are and which version this is.
println!("{} v{}", "Chatterbox", "0.1");
// Each {} is a hole. The values after the text fill the holes, in order.
println!("Hi {}! I'm {}.", "Sam", "Chatterbox");
println!("Type a message and I will answer.");
}
Chatterbox prints (a real run)
Chatterbox v0.1
Hi Sam! I'm Chatterbox.
Type a message and I will answer.

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

Read the two new println! lines aloud. The banner now fills two holes, a name and a version, instead of spelling out Chatterbox v0.1 in one piece. The greeting fills two holes with a person and the bot. The comment between them is a note for you, and the compiler skips it.

This version does not read anything you type yet: Sam comes from the code itself. Download the zip, change "Sam" to your own name, and cargo run it: that is a real edit to a real program. (A preview: at the end of chapter 3, Chatterbox learns to ask your name.)

Notice the repetition: "Chatterbox" appears twice. If the bot changed its name you would have to change it in two places and hope you found them both. Chapter 2 fixes exactly that, by giving values names.

Try itYour turn: a goodbye for anyone

A greeting needs a goodbye. Make farewell return Bye, Sam! Come back soon. for the name "Sam", and the same sentence with any other name filled in. The name arrives as name. As in the last exercise, the last line with no semicolon is what the function hands back, and right now that line is String::new(), empty text. Replace String::new() with a format!(…) that builds the sentence, and leave the semicolon off.

A greeting needs a goodbye. Make farewell return Bye, Sam! Come back soon. for the name "Sam", and the same sentence with any other name filled in. The name arrives as name. As in the last exercise, the last line with no semicolon is what the function hands back, and right now that line is String::new(), empty text. Replace String::new() with a format!(…) that builds the sentence, and leave the semicolon off.

fn farewell(name: &str) -> String {
// replace String::new() with format!: Bye, <name>! Come back soon.
String::new()
}
 
fn main() {
println!("{}", farewell("Sam"));
}

Hidden tests (3): says_bye_to_sam an_empty_name_still_makes_a_sentence says_bye_to_anyone

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

What you have now

You know what a program is, how to make and run a Rust project, how to print text with holes, and how to leave comments. Chatterbox greets you by name.

Before Chatterbox grows any further, the next lesson spends a few minutes on the compiler's messages: what each part of one means, and how to fix a program by reading them. After that, the last lesson of this chapter turns the banner and the greeting into functions of their own.

Self-check

Say it out loud, then reveal

Self-checkRetrieval beats re-reading
What did Chatterbox gain in this lesson?Reveal
A personal greeting: it prints a banner, then a line that fills in a name.
Why is typing "Chatterbox" twice a problem?Reveal
If the name changes you have to find and edit every copy. Chapter 2 introduces names for values to fix that.
What is the difference between println! and format! in the farewell exercise?Reveal
println! puts the text on the screen. format! builds the same text and hands it back, so farewell can return it for main to print.

That is lesson 1.4. Tick it off so the course remembers where you are.

Questions people ask

How do I put a variable inside a string in Rust?

Leave a hole {} in the text and pass the value after a comma, as in println!("Hi {}!", name). Each hole is filled in order, left to right.

How do I make a function return text in Rust?

Write -> String after the function name and build the text with format!. The last line of the function, with no semicolon, is the value it hands back.

What is a good first Rust project?

Something small you can grow one step at a time, like the Chatterbox chat program in this course. It starts as a greeting and gains one new idea per lesson.

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