Data Types

Core built-in types.

Quick reference

Most-used built-in types:

TypeExampleNotes
i324232-bit signed integer (default for literals)
i641000000000064-bit signed integer
booltrueBoolean
string"hi"UTF-8 text (heap-owned when dynamic)
voidNo 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)
}

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.

TypeBitsBytes (size_of)
i8 / u881
i16 / u16162
i32 / u32324
i64 / u64648
i128 / u12812816
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
}

Output

4
32
8
64

More: stdlib → size_of / align_of.