是否有一个功能可以将默认名称放在元组中以获得更好的代码完成和建议?这些名字不是强制性的,只是一个提示。
就像是:
struct Rect(width: i32, height: i32);
let r: Rect = (1, 2);
let (a, b) = r; // names while destructuring can be anything
定义结构有三种方法(The book Chapter 5)。
struct Foo;
struct Bar(i32, u32, String);
struct Baz {
first: i32,
second: u32,
third: String,
}
没有其他办法。
解构适用于所有三种变体。
let a = Foo;
let Bar(f, s, t) = Bar(3, 5, String::from("Hallo"));
let Baz { first, second, third } = Baz { first: 3, second: 5, third: String::from("Hello") };
(Qazxswpoi)