元组(Tuples)

1. fn main() {
2. let t: (i8, bool) = (7, true);
3. println!("t.0: {}", t.0);
4. println!("t.1: {}", t.1);
5. }

This slide should take about 5 minutes.

  • 和数组一样,元组也具有固定的长度。
  • 元组将不同类型的值组成一个复合类型。
  • 元组中的字段可以通过英文句号加上值的下标进行访问比如:t.0, t.1。
  • The empty tuple () is referred to as the “unit type” and signifies absence of a return value, akin to void in other languages.