Vibe Engines
YouTube

Lesson 2.3 · 8 min

Numbers and true/false

Chatterbox needs a token budget, a temperature and a quiet switch. Those are three different kinds of value, and Rust wants to know which kind each one is. That is a feature: it catches silly mistakes before the program runs.

Adds to ChatterboxA token budget and a "quiet" switch.

Every value has a type

So far every value was text. Values come in kinds, and the kind is called the type. Rust checks types before your program runs, so asking text to behave like a number is caught early. Three kinds cover most of what Chatterbox needs.

  • Whole numbers. u32 is a whole number that cannot be negative (the u is for unsigned). i32 is a whole number that can be. A token budget is u32: you cannot have minus ten tokens.
  • Decimal numbers. f64 is a number with a fractional part, such as a temperature of 0.7.
  • True or false. bool has exactly two values, true and false.
Writing the type after the name
fn main() {
let token_budget: u32 = 4096;
let temperature: f64 = 0.7;
let quiet: bool = false;
println!("{} {} {}", token_budget, temperature, quiet);
}
$ cargo run
4096 0.7 false

The : u32 after the name is the type. You can often leave it out, and Rust works it out from the value: a bare 0 becomes i32, a bare 0.7 becomes f64. Writing it is clearer when the choice matters, such as u32 for a budget.

Arithmetic, and one surprise

The usual symbols work: +, -, *, /. The surprise is in dividing whole numbers. A whole number has no room for a fraction, so the fraction is dropped.

PredictDivide two whole numbers
fn main() {
println!("{}", 7 / 2);
}

What does this print?

  • 3
  • 3.5
  • 4
Reveal the answer

The program prints: 3 Both sides are whole numbers, so the answer is a whole number: 7 divided by 2 is 3 with some left over, and the leftover is dropped. To get 3.5, at least one side must be a decimal, as in 7.0 / 2.0.

Decimals keep the fraction
fn main() {
println!("{}", 7.0 / 2.0);
}
$ cargo run
3.5

Comparing gives a bool

A bool usually comes from a comparison. > and < ask which is bigger, == asks whether two things are equal, and != asks whether they differ. Each answers with true or false.

Questions with yes/no answers
fn main() {
let used = 4100;
let budget = 4096;
println!("{}", used > budget);
println!("{}", used == budget);
}
$ cargo run
true
false

Right now a bool is only printed. In chapter 3 it decides what Chatterbox does next. Note that = assigns and == compares; they are different symbols on purpose.

Chatterbox v0.2, step three

The bot gets a token budget and a quiet switch, and prints both.

src/main.rs: Chatterbox v0.2, step three
fn main() {
let name = "Sam";
let bot = "Chatterbox";
let version = "0.2";
let mut message_count = 0;
let token_budget: u32 = 4096;
let quiet = false;
println!("{} v{}", bot, version);
println!("Hi {}! I'm {}.", name, bot);
message_count += 1;
println!("{} messages so far", message_count);
println!("Budget: {} tokens, quiet: {}", token_budget, quiet);
}
$ cargo run
Chatterbox v0.2
Hi Sam! I'm Chatterbox.
1 messages so far
Budget: 4096 tokens, quiet: false
Try itYour turn: over budget?

Make is_over_budget answer true only when used is strictly more than budget. Replace the placeholder with a comparison. You don't need to understand fn yet (chapter 3, lesson 4 explains it): just fill in the body.

Make is_over_budget answer true only when used is strictly more than budget. Replace the placeholder with a comparison. You don't need to understand fn yet (chapter 3, lesson 4 explains it): just fill in the body.

fn is_over_budget(budget: u32, used: u32) -> bool {
// true only when used is more than budget
false
}
 
fn main() {
println!("{}", is_over_budget(4096, 4100));
}

Hidden tests (3): exactly_at_budget_is_fine over under

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

Self-check

Say it out loud, then reveal

Self-checkRetrieval beats re-reading
What is 7 / 2 for whole numbers, and why?Reveal
3. Whole numbers have no fraction, so the remainder is dropped.
Which type would you pick for a token budget, and why?Reveal
u32: a whole number that can never be negative.
What is the difference between = and ==?Reveal
= gives a name a value. == compares two values and answers true or false.

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

Next: 2.4 Text →

Questions people ask

What is the difference between i32 and u32?

Both are 32-bit whole numbers. i32 can be negative; u32 cannot, which lets it reach twice as high.

Which number type does Rust choose by default?

i32 for whole numbers and f64 for decimals, when nothing else says otherwise.

Can I add a whole number and a decimal?

Not directly. Rust treats them as different types and asks you to convert one on purpose.

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