1
1
use serde:: { Deserialize , Serialize } ;
2
+ use std:: fmt;
2
3
3
4
use crate :: { error:: OxenError , model:: LocalRepository , util} ;
4
5
use std:: path:: PathBuf ;
@@ -11,12 +12,12 @@ pub enum SizeStatus {
11
12
Error ,
12
13
}
13
14
14
- impl ToString for SizeStatus {
15
- fn to_string ( & self ) -> String {
15
+ impl fmt :: Display for SizeStatus {
16
+ fn fmt ( & self , f : & mut fmt :: Formatter < ' _ > ) -> fmt :: Result {
16
17
match self {
17
- SizeStatus :: Pending => "pending" . to_string ( ) ,
18
- SizeStatus :: Done => "done" . to_string ( ) ,
19
- SizeStatus :: Error => "error" . to_string ( ) ,
18
+ SizeStatus :: Pending => write ! ( f , "pending" ) ,
19
+ SizeStatus :: Done => write ! ( f , "done" ) ,
20
+ SizeStatus :: Error => write ! ( f , "error" ) ,
20
21
}
21
22
}
22
23
}
@@ -27,9 +28,12 @@ pub struct RepoSizeFile {
27
28
pub size : u64 ,
28
29
}
29
30
30
- impl ToString for RepoSizeFile {
31
- fn to_string ( & self ) -> String {
32
- serde_json:: to_string ( self ) . unwrap_or_default ( )
31
+ impl fmt:: Display for RepoSizeFile {
32
+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
33
+ match serde_json:: to_string ( self ) {
34
+ Ok ( s) => write ! ( f, "{}" , s) ,
35
+ Err ( _) => write ! ( f, "" ) ,
36
+ }
33
37
}
34
38
}
35
39
@@ -38,26 +42,26 @@ pub fn update_size(repo: &LocalRepository) -> Result<(), OxenError> {
38
42
let size = match util:: fs:: read_from_path ( & path) {
39
43
Ok ( content) => match serde_json:: from_str :: < RepoSizeFile > ( & content) {
40
44
Ok ( parsed) => {
41
- let new_file = RepoSizeFile {
45
+
46
+ RepoSizeFile {
42
47
status : SizeStatus :: Pending ,
43
48
size : parsed. size ,
44
- } ;
45
- new_file
49
+ }
46
50
}
47
51
Err ( e) => {
48
- return Err ( OxenError :: basic_str ( & format ! (
52
+ return Err ( OxenError :: basic_str ( format ! (
49
53
"Failed to parse size file: {}" ,
50
54
e
51
55
) ) ) ;
52
56
}
53
57
} ,
54
58
Err ( e) => {
55
59
log:: info!( "Size file not found, creating it: {}" , e) ;
56
- let new_file = RepoSizeFile {
60
+
61
+ RepoSizeFile {
57
62
status : SizeStatus :: Pending ,
58
63
size : 0 ,
59
- } ;
60
- new_file
64
+ }
61
65
}
62
66
} ;
63
67
0 commit comments