Click a card to flip it · 9 terms
Every value in Rust has a specific type. This deck covers the primitive types: char for single characters, bool for true or false, and numeric types like i32, u32, f64, and usize.
char
bool
i32
u32
f64
usize
Rust's empty value, means "nothing"
When a function returns nothing meaningful
fn greet() { println!("hi"); }// returns () by default
true or false, nothing else
true
false
Status flags: is_paid, is_verified
is_paid
is_verified
let is_paid: bool = true;let is_verified: bool = false;
One character, single quotes
'A', '🔥', single symbols, not strings
'A'
'🔥'
let letter: char = 'A';let emoji: char = '🔥';
Prints a line to the terminal
Debugging or showing output
let name = "Alice";println!("Hello, {}!", name);
Debug print formatting
Printing arrays and tuples that {} cannot print
{}
let arr = [1, 2, 3];println!("{:?}", arr);
An array of exactly 32 unsigned bytes
Wallet addresses on Solana
let addr: [u8; 32] = [0; 32];println!("{:?}", addr);
An unsigned integer whose size matches the computer's architecture, 8 bytes on 64-bit
Used for memory sizes, slice lengths, and array indexes, the type Rust uses internally for positions
let len: usize = 32;let i: usize = 0;
Converting a value from one type to another using the as keyword, always explicit, never automatic
as
let x: i32 = 1000; let y = x as u8;
let x: i32 = 1000;let y = x as u8;
The numeric code that represents a character
'a' as u8 gives 97; 97u8 as char gives 'a'
'a' as u8
97
97u8 as char
'a'
let n: u8 = 'a' as u8;let c: char = 97u8 as char;