Generalize disk file creation logic
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
2025-05-29 08:03:42 +02:00
parent 7451f1b7b4
commit 20de618568
6 changed files with 103 additions and 58 deletions

View File

@ -0,0 +1,28 @@
#[derive(
serde::Serialize, serde::Deserialize, Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord,
)]
pub struct FileSize(usize);
impl FileSize {
pub const fn from_bytes(size: usize) -> Self {
Self(size)
}
pub const fn from_mb(mb: usize) -> Self {
Self(mb * 1000 * 1000)
}
pub const fn from_gb(gb: usize) -> Self {
Self(gb * 1000 * 1000 * 1000)
}
/// Get file size as bytes
pub fn as_bytes(&self) -> usize {
self.0
}
/// Get file size as megabytes
pub fn as_mb(&self) -> usize {
self.0 / (1000 * 1000)
}
}