diff options
| author | Ruben Beltran del Rio <git@r.bdr.sh> | 2025-01-05 15:48:16 +0100 |
|---|---|---|
| committer | Ruben Beltran del Rio <git@r.bdr.sh> | 2025-01-05 15:48:16 +0100 |
| commit | b17907faf8d9693cef94a6048d802bd4ced9102f (patch) | |
| tree | 1bd87c40e85af675a96b63672163b4caaa174364 /src/metadata.rs | |
| parent | d7fef30ac3f539975ef9edbba8e0af4a4e9ff3de (diff) | |
Deal with all lints
Diffstat (limited to 'src/metadata.rs')
| -rw-r--r-- | src/metadata.rs | 23 |
1 files changed, 11 insertions, 12 deletions
diff --git a/src/metadata.rs b/src/metadata.rs index e016db6..fe657e4 100644 --- a/src/metadata.rs +++ b/src/metadata.rs @@ -14,17 +14,16 @@ pub struct Metadata { impl Metadata { pub fn read_or_create(file_path: &PathBuf) -> Metadata { - match Metadata::read_metadata_file(file_path) { - Some(metadata) => metadata, - None => { - let timestamp = SystemTime::now() - .duration_since(UNIX_EPOCH) - .map(|duration| duration.as_millis() as u64) - .unwrap_or_else(|_| 0); - return Metadata { - id: timestamp.to_string(), - created_on: timestamp, - }; + if let Some(metadata) = Metadata::read_metadata_file(file_path) { + metadata + } else { + let timestamp = SystemTime::now().duration_since(UNIX_EPOCH).map_or_else( + |_| 0, + |duration| u64::try_from(duration.as_millis()).expect("Timestamp is too big!"), + ); + Metadata { + id: timestamp.to_string(), + created_on: timestamp, } } } @@ -32,7 +31,7 @@ impl Metadata { pub fn created_on_utc(&self) -> Option<String> { let date = OffsetDateTime::from_unix_timestamp_nanos((self.created_on * 1_000_000).into()).ok()?; - return date.format(&Rfc2822).ok(); + date.format(&Rfc2822).ok() } fn read_metadata_file(file_path: &PathBuf) -> Option<Metadata> { |