【发布时间】:2021-09-08 00:02:23
【问题描述】:
我在 Rust 中有这个功能:
fn printboard(board: Vec<u32>) {
println!("| |{:>2$} {:>2$} {:>2$} {:>2$} {:>2$} {:>2$}| |",
board[1], board[2], board[3], board[4], board[5], board[6]);
}
由于某种原因,代码在board[3] 处引发错误,提示“预期使用大小,发现 u32”。这不会发生在任何其他 board[x] 表达式中。知道为什么会这样吗?
这是完整的错误:
error[E0308]: mismatched types
--> src/lib.rs:3:29
|
3 | board[1], board[2], board[3], board[4], board[5], board[6]);
| ^^^^^^^^ expected `usize`, found `u32`
|
= note: expected reference `&usize`
found reference `&u32`
= note: this error originates in the macro `$crate::format_args_nl` (in Nightly builds, run with -Z macro-backtrace for more info)
【问题讨论】:
标签: rust