#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub struct MemoryInfo {
pub total_bytes: u64,
pub available_bytes: u64,
}
#[must_use]
pub(super) fn probe() -> MemoryInfo {
super::probe::platform::probe_memory()
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_default_total_bytes_is_zero() {
assert_eq!(MemoryInfo::default().total_bytes, 0);
}
#[test]
fn test_default_available_bytes_is_zero() {
assert_eq!(MemoryInfo::default().available_bytes, 0);
}
#[test]
fn test_probe_returns_non_zero_total_on_real_platforms() {
let m = probe();
if cfg!(any(
target_os = "linux",
target_os = "macos",
target_os = "windows"
)) {
assert!(
m.total_bytes > 0,
"real platforms must report >0 total memory"
);
} else {
assert_eq!(m, MemoryInfo::default());
}
}
#[test]
fn test_probe_returns_owned_value_each_call() {
let a = probe();
let b = probe();
assert_eq!(a.total_bytes, b.total_bytes);
}
}