Is it possible to unpack a tuple into function arguments?

There is a way, using the magic of pattern matching:

fn main() {
    let tuple = (10, Vec::new());
    foo(tuple);
}

fn foo((a, b): (i32, Vec<i32>)) {
    // do stuff
}

As per Rust reference:

As with let bindings, function arguments are irrefutable patterns, so
any pattern that is valid in a let binding is also valid as an
argument.

So you can specify an argument like:

(a, b): (i32, Vec<i32>)

just like you would in a let statement.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)