Change tuple (mutable)
-
mut
-
Use the
mut
keyword to make the values of the tuple mutable. -
We still cannot add elements to the tuple. It's shape and the types of the fields are fixed.
-
Assign a new value to one of the elements using the dot-notation.
fn main() { let mut row = ("Blue", 300, 3.67); println!("{:?}", row); row.0 = "Green"; row.1 = 99; println!("{:?}", row); }
("Blue", 300, 3.67)
("Green", 99, 3.67)