Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

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)