我可以像这样解压一个经典元组:
let pair = (1, true);
let (one, two) = pair;
如果我有一个元组结构,例如struct Matrix(f32, f32, f32, f32)
我尝试解压它,收到有关“意外类型”的错误:
struct Matrix(f32, f32, f32, f32);
let mat = Matrix(1.1, 1.2, 2.1, 2.2);
let (one, two, three, four) = mat;
结果出现此错误:
error[E0308]: mismatched types
--> src/main.rs:47:9
|
47 | let (one, two, three, four) = mat;
|
= note: expected type `Matrix`
found type `(_, _, _, _)`
如何解压元组结构?我需要将其显式转换为元组类型吗?或者我需要对其进行硬编码?