In the Rust Book, chapter 18, they give an example of a tuple versus a pattern.
fn print_coordinates(&(x, y): &(i32, i32)) {
println!("Current location: ({}, {})", x, y);
}
fn main() {
let point = (3, 5);
print_coordinates(&point);
}
Out of curiosity, I tried without going as a link like this.
fn print_coordinates((x, y): (i32, i32)) {
println!("Current location: ({}, {})", x, y);
}
fn main() {
let point = (3, 5);
print_coordinates(point);
print_coordinates(point);
}
It compiles and prints coordinates 2 times.
Can tuples be passed to functions in the same way as other primitive data types (numbers, Booleans, etc.)?
source
share