Types (v0.2.1)

Primitive and built-in type forms used by Thrust.

Latest

Overview

Thrust types are written explicitly. Integers, floats, pointers, arrays, function references, and void all appear directly in source code.

This makes declarations easy to read. When a function takes u32, ptr[s32], or array[char; 64], the size and shape of the value are visible at the call boundary.

Use concrete types in public APIs unless there is a clear reason to introduce a type alias or a generic parameter.

Primary source: syntax/types/

Syntax Signatures

var signed: s32 = -1;
var unsigned: u64 = 1;
var decimal: f64 = 3.14;
var bufferPtr: ptr[u8] = nullptr;
var dynamic: array[s32] = [1, 2, 3];
var fixedValues: array[u16; 4] = fixed[0, 1, 2, 3];

Behavior and Use

Fixed-width integers are best for public APIs and binary formats because their size is part of the name.

Pointers and arrays mean different things. A pointer refers to memory elsewhere, while an array type describes a sequence of elements.

Best Practices

Scalar Types

Scalar values are stored directly and are usually passed by value.

Pointer and Array Types

Pointer and array syntax makes memory shape visible at the use site.

Aliases and Layout

Aliases and layout builtins help keep public declarations readable without hiding representation.

Example

fn main() s32 @public {
    var values: array[s32; 3] = fixed[2, 4, 6];

    var sum: s32 =
        (deref values[0]) +
        (deref values[1]) +
        (deref values[2]);

    return sum;
}

Back to language reference