In the Rust Book, Chapter 18, they give an example of a tuple in pattern matching.
fn print_coordinates(&(x, y): &(i32, i32)) {
println!("Current location: ({}, {})", x, y);
}
fn main() {
let point = (3, 5);
print_coordinates(&point); // point passed as reference
}
Out of curiosity, I tried without passing as a reference like this.
fn print_coordinates((x, y): (i32, i32)) {
println!("Current location: ({}, {})", x, y);
}
fn main() {
let point = (3, 5);
print_coordinates(point); // point passed as value
print_coordinates(point); // point is still valid here
}
It compiles and prints out the coordinates 2 times.
Can tuples be passed into functions just like other primitive data types (numbers, booleans, etc.)?