I want to initialize two fields from a tuple returned from a function:
#[derive(Clone, Copy, Debug)]
struct Point {
x: f64,
y: f64,
z: f64,
}
fn f() -> (f64, f64) {
(5., 6.)
}
fn main() {
let mut p = Point {
x: 1.,
y: 2.,
z: 3.,
};
println!("{:?}", p);
match f() {
(x, y) => {
p.x = x;
p.y = y;
}
}
println!("{:?}", p);
}
The obvious code (p.x, p.y) = f()
did not compile so I have to use match
. Do you have any idea how to make the match
assignment simpler to read?
I want to
- Call
f
only once per assignment of the two fields - Have
f
on the right side, andp.x
andp.y
and the left side, not how it is inmatch
now