Skip to content

Commit 681da35

Browse files
committed
clippy
1 parent a25d005 commit 681da35

File tree

1 file changed

+19
-15
lines changed

1 file changed

+19
-15
lines changed

src/lib/src/repositories/size.rs

+19-15
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use serde::{Deserialize, Serialize};
2+
use std::fmt;
23

34
use crate::{error::OxenError, model::LocalRepository, util};
45
use std::path::PathBuf;
@@ -11,12 +12,12 @@ pub enum SizeStatus {
1112
Error,
1213
}
1314

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 {
1617
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"),
2021
}
2122
}
2223
}
@@ -27,9 +28,12 @@ pub struct RepoSizeFile {
2728
pub size: u64,
2829
}
2930

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+
}
3337
}
3438
}
3539

@@ -38,26 +42,26 @@ pub fn update_size(repo: &LocalRepository) -> Result<(), OxenError> {
3842
let size = match util::fs::read_from_path(&path) {
3943
Ok(content) => match serde_json::from_str::<RepoSizeFile>(&content) {
4044
Ok(parsed) => {
41-
let new_file = RepoSizeFile {
45+
46+
RepoSizeFile {
4247
status: SizeStatus::Pending,
4348
size: parsed.size,
44-
};
45-
new_file
49+
}
4650
}
4751
Err(e) => {
48-
return Err(OxenError::basic_str(&format!(
52+
return Err(OxenError::basic_str(format!(
4953
"Failed to parse size file: {}",
5054
e
5155
)));
5256
}
5357
},
5458
Err(e) => {
5559
log::info!("Size file not found, creating it: {}", e);
56-
let new_file = RepoSizeFile {
60+
61+
RepoSizeFile {
5762
status: SizeStatus::Pending,
5863
size: 0,
59-
};
60-
new_file
64+
}
6165
}
6266
};
6367

0 commit comments

Comments
 (0)