Scalar & Compound Types
Scalar Types
- Integers: Signed (
i8,i32,i128) and Unsigned (u8,u32,u128). Useusize/isizefor architecture-dependent sizes (memory addresses). - Floating-Point:
f32andf64(default). - Booleans:
trueandfalse. - Characters:
charrepresents a Unicode scalar value (4 bytes).
Compound Types
-
Tuples: Group multiple values of different types. rust let tup: (i32, f64, u8) = (500, 6.4, 1);
-
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.