1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
use std::fmt;
#[derive(Clone)]
pub enum Block {
Raw(Box<[u8; Block::SIZE as usize]>),
Fill([u8; 4]),
Skip,
Crc32(u32),
}
impl Block {
pub const SIZE: u32 = 4096;
}
impl fmt::Debug for Block {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
use Block::*;
match self {
Raw(r) => write!(f, "Raw({:?})", &r[..]),
Fill(_) | Skip | Crc32(_) => self.fmt(f),
}
}
}
impl PartialEq for Block {
fn eq(&self, other: &Self) -> bool {
use Block::*;
match (self, other) {
(Raw(r1), Raw(r2)) => r1[..] == r2[..],
(Fill(v1), Fill(v2)) => v1 == v2,
(Skip, Skip) => true,
(Crc32(c1), Crc32(c2)) => c1 == c2,
_ => false,
}
}
}