How can I assign an element of a tuple to an existing variable?

I'm trying to do something like

let (x, y) = returns_tuple();

but I do not want the elements of the tuple to be assigned to new variables. How is this done?

Playground link

Rust doesn't have destructuring assignment. If you wan to reassign existing variables you will have to:

let tmp = returns_tuple();
x = tmp.0;
y = tmp.1;
1 Like

Alright, thanks.

There is an RFC for destructuring assignment, and it is implemented on the nightly channel behind the #![feature(destructuring_assignment)] feature gate.

Based on the tracking issue, the implementation is fairly complete and could be proposed for stabilization. The next step is for someone to write a stabilization report.


This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.