1use crate::prelude::{Reading, Result};
2
3#[derive(Clone, Copy, PartialEq, PartialOrd)]
4pub struct Padding<const N: usize>(pub [u8; N]);
5
6impl<const N: usize> From<[u8; N]> for Padding<N> {
7 fn from(bytes: [u8; N]) -> Self {
8 Self(bytes)
9 }
10}
11
12impl<const N: usize> Default for Padding<N> {
13 fn default() -> Self {
14 Self([0u8; N])
15 }
16}
17
18impl<const N: usize> std::fmt::Debug for Padding<N> {
19 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
20 if self.is_empty() {
21 f.write_fmt(format_args!("Padding({} bytes) - EMPTY", N))
22 } else {
23 f.write_fmt(format_args!("Padding({} bytes) - NOT EMPTY", N))
24 }
25 }
26}
27
28impl<const N: usize> Padding<N> {
29 pub fn is_empty(&self) -> bool {
30 self.0.iter().all(|value| value == &0)
31 }
32}
33
34impl<T, const N: usize> Reading<Padding<N>> for T
35where
36 T: Reading<u8>,
37{
38 const SIZE: usize = <T as Reading<u8>>::SIZE * N;
39
40 fn read_one(&mut self) -> Result<Padding<N>> {
41 let bytes = self.read()?;
42 Ok(Padding(bytes))
43 }
44}