【发布时间】:2021-09-28 02:42:54
【问题描述】:
这个程序很好:
const EMPTY: i32 = 0;
const SIZEX: usize = 4;
const SIZEY: usize = 4;
fn main() {
let mut test = vec![[EMPTY; SIZEY]; SIZEX];
test[2][3] = 4;
// test.what();
println!("Hello, world:{}", test[2][3]);
}
当我取消注释 test.what() 行以查看 test 的类型时,编译器会发出错误:
error[E0599]: no method named `what` found for struct `Vec<[i32; 4]>` in the current scope
--> src/main.rs:8:10
|
8 | test.what();
| ^^^^ method not found in `Vec<[i32; 4]>`
我期待test 的类型类似于Vec<[[i32; SIZEY]; SIZEX]>。我错过了什么?
【问题讨论】:
-
.what()是什么? -
这里查看的类型是the array primitive 和
std::vec::Vec。可能都值得在这里阅读。
标签: rust