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

Create tuple with types, but without values

  • mut

  • We can create a tuple without initializing. In this case it seems even more useful to declare the types. (Though not required.)

  • We must have the mut keyword to make it mutable.

  • Then later we can assign all the values at once.

  • Before we initialize all the values we cannot assign them one-by-one.

fn main() {
    let mut row: (&str, i32, f32);

    // row.0 = "Blue";
    // partially assigned binding `row` isn't fully initialized

    row = ("Purple", 300, 3.45);
    println!("{:?}", row);

    row = ("Green", 99, 4.1);
    println!("{:?}", row);
}
("Purple", 300, 3.45)
("Green", 99, 4.1)