feat: Postgresql score based on the postgres capability now. true infrastructure abstraction!
Some checks failed
Run Check Script / check (pull_request) Failing after 33s

This commit is contained in:
2025-12-16 23:35:52 -05:00
parent b0383454f0
commit 440e684b35
14 changed files with 244 additions and 104 deletions

View File

@@ -5,6 +5,8 @@ use std::fmt;
pub struct StorageSize {
size_bytes: u64,
#[serde(skip)]
display_value: Option<u64>,
#[serde(skip)]
display_suffix: Option<String>,
}
@@ -12,6 +14,7 @@ impl StorageSize {
pub fn new(size_bytes: u64) -> Self {
Self {
size_bytes,
display_value: None,
display_suffix: None,
}
}
@@ -19,6 +22,7 @@ impl StorageSize {
pub fn b(size: u64) -> Self {
Self {
size_bytes: size,
display_value: Some(size),
display_suffix: Some("B".to_string()),
}
}
@@ -26,6 +30,7 @@ impl StorageSize {
pub fn kb(size: u64) -> Self {
Self {
size_bytes: size * 1024,
display_value: Some(size),
display_suffix: Some("KB".to_string()),
}
}
@@ -33,6 +38,7 @@ impl StorageSize {
pub fn mb(size: u64) -> Self {
Self {
size_bytes: size * 1024 * 1024,
display_value: Some(size),
display_suffix: Some("MB".to_string()),
}
}
@@ -40,6 +46,7 @@ impl StorageSize {
pub fn gb(size: u64) -> Self {
Self {
size_bytes: size * 1024 * 1024 * 1024,
display_value: Some(size),
display_suffix: Some("GB".to_string()),
}
}
@@ -47,13 +54,15 @@ impl StorageSize {
pub fn gi(size: u64) -> Self {
Self {
size_bytes: size * 1024 * 1024 * 1024,
display_suffix: Some("GiB".to_string()),
display_value: Some(size),
display_suffix: Some("Gi".to_string()),
}
}
pub fn tb(size: u64) -> Self {
Self {
size_bytes: size * 1024 * 1024 * 1024 * 1024,
display_value: Some(size),
display_suffix: Some("TB".to_string()),
}
}
@@ -61,6 +70,7 @@ impl StorageSize {
pub fn ti(size: u64) -> Self {
Self {
size_bytes: size * 1024 * 1024 * 1024 * 1024,
display_value: Some(size),
display_suffix: Some("TiB".to_string()),
}
}
@@ -73,7 +83,8 @@ impl StorageSize {
impl fmt::Display for StorageSize {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
if let Some(suffix) = &self.display_suffix {
write!(f, "{}{}", self.size_bytes, suffix)
let value = self.display_value.unwrap_or(self.size_bytes);
write!(f, "{}{}", value, suffix)
} else {
write!(f, "{}B", self.size_bytes)
}
@@ -95,42 +106,42 @@ mod tests {
fn test_kilobytes() {
let size = StorageSize::kb(2);
assert_eq!(size.bytes(), 2048);
assert_eq!(size.to_string(), "2048KB");
assert_eq!(size.to_string(), "2KB");
}
#[test]
fn test_megabytes() {
let size = StorageSize::mb(3);
assert_eq!(size.bytes(), 3 * 1024 * 1024);
assert_eq!(size.to_string(), "3145728MB");
assert_eq!(size.to_string(), "3MB");
}
#[test]
fn test_gigabytes() {
let size = StorageSize::gb(4);
assert_eq!(size.bytes(), 4 * 1024 * 1024 * 1024);
assert_eq!(size.to_string(), "4294967296GB");
assert_eq!(size.to_string(), "4GB");
}
#[test]
fn test_gibibytes() {
let size = StorageSize::gi(1);
assert_eq!(size.bytes(), 1024 * 1024 * 1024);
assert_eq!(size.to_string(), "1073741824GiB");
assert_eq!(size.to_string(), "1Gi");
}
#[test]
fn test_terabytes() {
let size = StorageSize::tb(5);
assert_eq!(size.bytes(), 5 * 1024 * 1024 * 1024 * 1024);
assert_eq!(size.to_string(), "5497558138880TB");
assert_eq!(size.to_string(), "5TB");
}
#[test]
fn test_tebibytes() {
let size = StorageSize::ti(1);
assert_eq!(size.bytes(), 1024 * 1024 * 1024 * 1024);
assert_eq!(size.to_string(), "1099511627776TiB");
assert_eq!(size.to_string(), "1Ti");
}
#[test]
@@ -155,6 +166,6 @@ mod tests {
fn test_ord() {
let one_gb = StorageSize::gb(1);
let one_gi = StorageSize::gi(1);
assert!(one_gb < one_gi); // 1GB = 1000MB, 1GiB = 1024MB
assert!(one_gb < one_gi); // 1GB = 1000MB, 1Gi = 1024MB
}
}