如何检查2 [u8; 256]
个数组是否相等(即所有元素是否相同)?编译器告诉我PartialEq
没有实现,但如果我尝试实现它,那么它会告诉我类型没有在包中定义。
fn main() {
let a1: [u8; 256] = [0; 256];
let a2: [u8; 256] = [0; 256];
println!("a1 equals a2 is: {}", a1 == a2);
}
输出结果为:
error[E0369]: binary operation `==` cannot be applied to type `[u8; 256]`
--> src/main.rs:5:37
|
5 | println!("a1 equals a2 is: {}", a1 == a2);
| ^^^^^^^^
|
= note: an implementation of `std::cmp::PartialEq` might be missing for `[u8; 256]`
这适用于较小尺寸的阵列,因此让我感到困惑。