πŸ”’
World 3 Β· Building Blocks

Kinds of Data (Types)

Think about a fruit basket. An apple, a banana, and a grape are all fruit, but they’re different kinds of fruit. In Rust, the values you store also come in different kinds. We call those kinds types. πŸ”’

The everyday types

Here are the ones you’ll meet most often:

  • i32 β€” a whole number, like 10 or -3. (No decimal point.)
  • f64 β€” a decimal number, like 3.14 or 0.5.
  • bool β€” a true-or-false value: true or false.
  • char β€” a single character, like 'A' or 'πŸ¦€'. (Use single quotes!)
New word A type is the kind of data a value is β€” a whole number, a decimal, a true/false, a letter, and so on.

What about words?

A piece of text is called a string. You write it inside double quotes, like "hello". There are two flavors you’ll hear about: &str (a quick borrowed bit of text) and String (text you can grow and change). For now, just remember: text goes in double quotes. πŸ“

The little : i32 after a name tells Rust the type. Most of the time Rust can guess the type on its own, but writing it out makes things extra clear. πŸŽ‰

Groups of values: tuples and arrays

Sometimes you want to keep a few values together:

  • A tuple holds a small mix of different things: (10, "ten", true).
  • An array holds a list of the same kind of thing: [1, 2, 3].
Think of it like this… A tuple is like a meal deal with a sandwich, a drink, and a side β€” all different things bundled together. An array is like an egg carton β€” every slot holds the same kind of thing. πŸ₯š
Try this! Add a line that makes a decimal called let pi: f64 = 3.14; and print it. Press β–Ά Run to see your decimal appear!

Quick quiz

Which type would you use for the value true?

Yes! A bool holds a true-or-false value. πŸ‘

You learned… Every value has a type: whole numbers (i32), decimals (f64), true/false (bool), single letters (char), and text (&str / String). Next up: building little machines called functions! βš™οΈ