File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -4,13 +4,38 @@ use walkdir::WalkDir;
44
55use super :: types:: { ArtifactCandidate , Size } ;
66
7- pub fn total_size ( artifacts : & [ ArtifactCandidate ] ) -> Size {
8- let total = artifacts
7+ pub trait Sizable {
8+ fn get_size ( & self ) -> & Size ;
9+ fn bytes ( & self ) -> & u64 {
10+ match self . get_size ( ) {
11+ Size :: UnknownSize => & 0 ,
12+ Size :: KnownSize ( b) => b,
13+ }
14+ }
15+ }
16+
17+ impl Sizable for ArtifactCandidate {
18+ fn get_size ( & self ) -> & Size {
19+ & self . size
20+ }
21+ }
22+
23+ impl Sizable for Size {
24+ fn get_size ( & self ) -> & Size {
25+ & self
26+ }
27+ }
28+
29+ impl Sizable for & Size {
30+ fn get_size ( & self ) -> & Size {
31+ self
32+ }
33+ }
34+
35+ pub fn total_size ( sizables : & [ impl Sizable ] ) -> Size {
36+ let total = sizables
937 . iter ( )
10- . fold ( 0 , |acc, artifact| match & artifact. size {
11- Size :: UnknownSize => acc,
12- Size :: KnownSize ( size) => acc + size,
13- } ) ;
38+ . fold ( 0 , |acc, artifact| acc + artifact. bytes ( ) ) ;
1439 Size :: KnownSize ( total)
1540}
1641
You can’t perform that action at this time.
0 commit comments