expression

Rust Read tuple elements by position

Tuple positions are accessed with a dot followed by a literal numeric index. This is useful when a small group holds values of different types. Expected output (not executed): 21 C Why: The first field is an integer and the second is a string slice. Common mistake: A tuple is not an array: `reading[0]` is not ordinary tuple indexing.

Formal Syntax & Structure

rust syntaxrust
tuple.0; tuple.1

Working Example

Example Snippetrust
fn main() {    let reading = (21, "C");    println!("{} {}", reading.0, reading.1);}
Rust Reference