想要改进这个问题? 更新问题,以便 editing this post 可以用事实和引用来回答它.
关闭 1 年前。
如题。
在 Rust 中,我需要使用句点语法来访问元组中的元素,如下所示(x.0
):
fn main() {
let x: (i32, f64, u8) = (500, 6.4, 1);
println!("{}", x.0);
}
我的问题是为什么 Rust 不支持使用方括号语法来访问元组内的元素,如下所示,这应该是一种更一致的方式?
fn main() {
// !!! this snippet of code would not be compiled !!!
let x: (i32, f64, u8) = (500, 6.4, 1);
println!("{}", x[0]); // pay attention to the use of "x[0]" here.
}