Skip to main content Link Search Menu Expand Document (external link)

Compound datatypes

  1. Array
    • Continuous group of items
    • fixed length
    • Length known at compile time
    • homogeneous

Syntax:-

let array: [u32; 3] = [1,2,3];

let first_item = array[0];
let will_warn = array[100]; // compiler will warn while at runtime it will crash
  1. Tuples
    • Linear group of items
    • fixed length
    • length known at compile time
    • heterogenous
    • Empty tuple is called unit
let tuple: (bool, u16, u8) = (true, 2, 3);

let first_item = tuple.0;
let error = tuple.100; // will give error