Skip to content
Apoorv Singal edited this page Aug 30, 2020 · 1 revision

A tuple is a user-defined data type that stores a group of values of different types.

Defining a tuple type

Tuple types are defined using the tuple keyword.

tuple Name {type1, type2, type3};

Using a tuple

tuple Tuple{u8, u32};

var: Tuple; // declares var of type Tuple
var := (Tuple){0, 1}; // initializes var with values 0 and 1

Accessing individual elements

Elements of a tuple are accessed just like arrays with the syntax of tupl[index]. There is only one restriction, index must be an integer literal.


Tuples are allocated on stack by default. See heap for details on how to allocate tuples on the heap.

Clone this wiki locally