Topic
Variables
Every value has a name and a type. Rust makes you explicit about both.
Quick Reference
Concept What it means
let x = 5 Declare a variable and give it a value
let mut x = 5 Declare a variable you can change later
i32 A whole number — can be positive or negative
u64 A whole number — always positive, used for lamports
Scope A variable only exists inside the { } block where it was declared
Shadowing Declaring a new variable with the same name — the new one takes over
Destructuring Unpacking a tuple into separate variables in one line
Term What it means When you use it
let Creates a new variable Every time you store a value
mut Allows a variable to change after it is set When your program needs to update state
u64 Unsigned 64-bit integer - whole number, no negatives Payment amounts, token balances, timestamps
u8 Unsigned 8-bit integer - whole number 0 to 255 Bytes, wallet address components
bool True or false - nothing else Status flags: is_paid, is_verified
[u8; 32] An array of 32 unsigned bytes Wallet addresses on Solana
&str A piece of text Labels, names, error messages
f64 A decimal number Rarely used in Solana - integer math is preferred
as Converts one type to another When you need to use two different types together