Why an uninitialized tuple cannot be initialized inside a block

fn main() {
    let (res, res02): (&str, &str);
    {
        (res, res02) = ("hi", "why");
    }
    println!("{}-{}", res, res02);
}

An uninitialized tuple can be initialized inside a block. The problem is you cant destructure a tuple outside of let, for now. The code below works fine:

fn main() {
    let res: (&str, &str);
    {
        res = ("hi", "why");
    }
    println!("{}-{}", res.0, res.1);
}
1 Like

Good to learn. Thanks.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.