Back to course

Primitive Data Types

Rust for Systems & Web3 Security

Scalar & Compound Types

Scalar Types

  1. Integers: Signed (i8, i32, i128) and Unsigned (u8, u32, u128). Use usize/isize for architecture-dependent sizes (memory addresses).
  2. Floating-Point: f32 and f64 (default).
  3. Booleans: true and false.
  4. Characters: char represents a Unicode scalar value (4 bytes).

Compound Types

  1. Tuples: Group multiple values of different types. rust let tup: (i32, f64, u8) = (500, 6.4, 1);

  2. Arrays: Fixed-length list of the same type. rust let a = [1, 2, 3, 4, 5];

In Web3 security, understanding integer overflows (e.g., using u8 when you need u16) is critical to prevent exploits.