Skip to content

Tuples

Tuples allow for the definition of a set of types, without having to define an explicit struct for it. These do not have any associated ID, meaning the order of declaration matters, and any modification to the type definition is generally incompatible.

The minimum amount of types in a tuple are 2 and the maximum are 12. Reasons for this choice are:

  • A tuple with 0 types is empty and can’t carry any data.
  • Having only 1 type is equivalent to the contained type itself and is redundant.
  • Up to 12 types seems arbitrary, but having more than 3 or 4 types often calls for defining an explicit struct with field names for better clarity.

In the schema, tuples are declared with parenthesis ( and ), each type separated by a comma ,, forming a definition like (T1, T2, TN...).

struct Sample {
size: (u32, u32) @1,
}
struct Sample {
size: (u32, u32),
}

In Rust we have tuples and they look the same as in the schema, minus the ID.

There is no native support for tuples. Thus, types for tuples should be provided as part of the encompassing library, for up to N types.

Again, no native support for tuples. The Map.Entry interface exists, but seems not to be meant as tuple replacement. Therefore, generic types should be provided together with the library, for up to N types.

Typescript has support for tuples, defined as [T1, T2, TN...].

Python has support for tuples, defined as tuple[T1, T2, TN...].