📦 Rust Data Types


✨ Scalar Types

Scalar types represent a single value. There are four:

  • i32, u64, etc. — Integers (signed & unsigned)
  • f32, f64 — Floating-point numbers
  • bool — true or false
  • char — a single character like 'a', '🦀'
rust
Loading…

Rust will infer types if you don't specify them (when it makes sense):

rust
Loading…

🧱 Compound Types

Compound types can hold multiple values. Two big ones:

1. Tuples

Group different types together.

rust
Loading…

2. Arrays

Fixed-size lists of same-type values.

rust
Loading…

🧠 Type Annotations: When & Why?

Sometimes, Rust needs a little help figuring things out:

rust
Loading…

Be explicit when:

  • You call .parse()
  • You want clarity in your code
  • You’re working with multiple number types

🎯 Summary

  • Scalar types: i32, f64, bool, char
  • Compound types: tuple, array
  • Rust infers most types unless it gets confused
  • Use type annotations when needed for clarity or to satisfy the compiler