expression

Rust Destructuring assignment and swapping

Update existing places together using destructuring assignment. This differs from a `let` pattern, which introduces bindings. The right-hand value is evaluated before the assignments. Expected output (not executed): 8 3 Why: The tuple on the right holds the old values before the destinations change. Common mistake: Using `let (left, right)` would introduce new bindings instead of updating the existing ones.

Formal Syntax & Structure

rust syntaxrust
(a, b) = (new_a, new_b);

Working Example

Example Snippetrust
fn main() {    let mut left = 3;    let mut right = 8;    (left, right) = (right, left);    println!("{left} {right}");}
Rust Reference