相关疑难解决方法(0)

为什么println!仅适用于长度小于33的数组?

在Rust中,这有效:

fn main() {
    let a = [0; 32];
    println!("{:?}", a);
}
Run Code Online (Sandbox Code Playgroud)

但这不是:

fn main() {
    let a = [0; 33];
    println!("{:?}", a);
}
Run Code Online (Sandbox Code Playgroud)

编译错误:

error[E0277]: the trait bound `[{integer}; 33]: std::fmt::Debug` is not satisfied
 --> src/main.rs:3:22
  |
3 |     println!("{:?}", a);
  |                      ^ the trait `std::fmt::Debug` is not implemented for `[{integer}; 33]`
  |
  = note: `[{integer}; 33]` cannot be formatted using `:?`; if it is defined in your crate, add `#[derive(Debug)]` or manually implement it
  = note: required by …
Run Code Online (Sandbox Code Playgroud)

arrays println rust

25
推荐指数
1
解决办法
1290
查看次数

标签 统计

arrays ×1

println ×1

rust ×1