-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathentry.rs
More file actions
78 lines (69 loc) 路 1.39 KB
/
Copy pathentry.rs
File metadata and controls
78 lines (69 loc) 路 1.39 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
use super::*;
#[allow(clippy::arbitrary_source_item_ordering)]
#[derive(Clone, Debug, Decode, Encode, EnumDiscriminants, PartialEq)]
#[strum_discriminants(
allow(clippy::arbitrary_source_item_ordering),
derive(Display),
name(EntryType),
strum(serialize_all = "kebab-case")
)]
pub enum Entry {
#[n(0)]
File {
#[n(0)]
hash: Hash,
#[n(1)]
size: u64,
},
#[n(1)]
Directory {
#[n(0)]
hash: Hash,
#[n(1)]
size: u64,
#[n(2)]
totals: Totals,
},
}
impl Entry {
pub fn directory(hash: Hash, size: u64, totals: Totals) -> Self {
Self::Directory { hash, size, totals }
}
pub fn file(hash: Hash, size: u64) -> Self {
Self::File { hash, size }
}
pub fn hash(&self) -> Hash {
match self {
Self::File { hash, .. } | Self::Directory { hash, .. } => *hash,
}
}
pub fn size(&self) -> u64 {
match self {
Self::File { size, .. } | Self::Directory { size, .. } => *size,
}
}
pub fn ty(&self) -> EntryType {
self.discriminant()
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn encoding() {
assert_encoding(Entry::File {
size: 100,
hash: Hash::bytes(b"foo"),
});
assert_encoding(Entry::Directory {
hash: Hash::bytes(b"foo"),
size: 100,
totals: Totals {
directories: 1,
directory_size: 50,
file_size: 200,
files: 3,
},
});
}
}