为大数组类型实现调试特性

Implement Debug trait for large array type

gather Rust 为大小为 32 和更小的数组提供调试实现。

我还 gather 我可以通过简单地使用带有非常长的格式说明符的 write! 在更大的数组上实现调试。但是我想知道有没有更好的方法。

为长度为 1024 的数组实现调试的推荐方法是什么?

use std::fmt;

struct Array<T> {
    data: [T; 1024]
}

impl<T: fmt::Debug> fmt::Debug for Array<T> {
    fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
        self.data[..].fmt(formatter)
    }
}

fn main() {
    let array = Array { data: [0u8; 1024] };

    println!("{:?}", array);
}

无法为 [T; 实施调试; 1024] 或一些具体类型的数组(即 [u8; 1024]。为其他板条箱的类型实现其他板条箱的特征,或为通用类型实现另一个板条箱的特征,都是设计所不允许的,