Beginner question: destructuring assignment and mutability

⚓ Rust    📅 2025-09-08    👤 surdeus    👁️ 2      

surdeus

I just started learning Rust. The following code runs without error. May someone please explain why let (x,y) instead of let (mut x, mut y) is the correct code? I get a compiler warning saying mut x and mut y don't need to be mutable if I use the let (mut x, mut y) version.

fn main() {
    let (x, y);
    (x, ..) = (3, 4);
    [.., y] = [1, 2];
    assert_eq!([x, y], [3, 2]);
    println!("Hello, world!");
}

2 posts - 2 participants

Read full topic

🏷️ Rust_feed