Data Types
Core built-in types.
Quick reference
Most-used built-in types:
| Type | Example | Notes |
|---|---|---|
i32 | 42 | 32-bit signed integer (default for literals) |
i64 | 10000000000 | 64-bit signed integer |
bool | true | Boolean |
string | "hi" | UTF-8 text (heap-owned when dynamic) |
void | — | No return value |
Examples by type
You can write the type explicitly or let the compiler infer it.
fn main() {
let count = 42
let flag = true
let name = "Nyra"
print(count)
print(flag)
print(name)
}fn main() -> void {
let count: i32 = 42
let flag = true
let name: string = "Nyra"
print(count)
print(flag)
print(name)
}Output
42
true
Nyra
Type sizes (bytes & bits)
The number in the type name is its width in bits: i32 is 32 bits, i64 is 64 bits. Use the compiler intrinsic size_of<T>() to get the size in bytes (multiply by 8 for bits). No import needed.
| Type | Bits | Bytes (size_of) |
|---|---|---|
i8 / u8 | 8 | 1 |
i16 / u16 | 16 | 2 |
i32 / u32 | 32 | 4 |
i64 / u64 | 64 | 8 |
i128 / u128 | 128 | 16 |
fn main() {
let num = 10
let num2 = 20
print(size_of<i32>()) // 4 bytes
print(size_of<i32>() * 8) // 32 bits
print(size_of<i64>()) // 8 bytes
print(size_of<i64>() * 8) // 64 bits
}fn main() -> void {
let num: i32 = 10
let num2: i32 = 20
print(size_of<i32>()) // 4 bytes
print(size_of<i32>() * 8) // 32 bits
print(size_of<i64>()) // 8 bytes
print(size_of<i64>() * 8) // 64 bits
}Output
4
32
8
64
More: stdlib → size_of / align_of.