Rust 1.50.0 稳定版发布,改进数组索引
Rust 1.50.0 稳定版已发布,此版本改进了数组索引、扩展了对联合字段 (union field) 的安全访问,并将其添加到标准库。 具备 const-generic 特性的数组索引 此版本为任意长度const N的数组[T; N]增加了ops::Index和IndexMut实现,索引操作符[]可通过内置的 compiler magic 在数组中运行。 fn second<C>(container: &C) -> &C::Output where C: std::ops::Index<usize> + ?Sized, { &container[1] } fn main() { let array: [i32; 3] = [1, 2, 3]; assert_eq!(second(&array[..]), &2); // slices worked before assert_eq!(second(&array), &2); // now it also works dir...