How can I unpack a tuple struct like I would a classic tuple?

Viewed 2546

I can unpack a classic tuple like this:

let pair = (1, true);
let (one, two) = pair;

If I have a tuple struct such as struct Matrix(f32, f32, f32, f32) and I try to unpack it, I get an error about "unexpected type":

struct Matrix(f32, f32, f32, f32);
let mat = Matrix(1.1, 1.2, 2.1, 2.2);
let (one, two, three, four) = mat;

Results in this error:

error[E0308]: mismatched types
  --> src/main.rs:47:9
   |
47 |     let (one, two, three, four) = mat;
   |
   = note: expected type `Matrix`
              found type `(_, _, _, _)`

How can I unpack a tuple struct? Do I need to convert it explicitly to a tuple type? Or do I need to hardcode it?

1 Answers
Related