Tuple in Cairo#
The version of the Cairo compiler used in this article: 2.0.0-rc0. Because Cairo is being updated rapidly, the syntax may vary slightly in different versions, and the content of the article will be updated to the stable version in the future.
A tuple is an interesting type that many programming languages have. It allows multiple different types to be combined into one collection. Once declared, the number of types it contains cannot be increased or decreased, and the types inside it cannot be changed.
Basic Usage#
use debug::PrintTrait;
fn main() {
let tup: (u32, u64, bool) = (10, 20, true);
let (x, y, z) = tup;
x.print();
}
In the above code, a tuple is created that contains three types: u32, u64, bool
. let (x, y, z) = tup;
demonstrates how the elements in the tuple are extracted.