Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to have a vector of tuples that are varying length?

Tags:

rust

Something like this:

let vector = vec![(1, 2), ("A", 2, 3)];

If this isn't possible, what other alternatives could I use? For the sake of example, assume the length of the vector is unknown and the length of tuples is between 1 - 5 elements.

like image 383
Caballero Avatar asked Oct 18 '25 11:10

Caballero


1 Answers

Use a enum with variants for each desired tuple length (and each allowed combination of component types if necessary).

like image 150
Alexey Romanov Avatar answered Oct 21 '25 03:10

Alexey Romanov