use heim_common::units::{information, Information};
use crate::Memory;
pub trait MemoryExt {
fn used(&self) -> Information;
fn buffers(&self) -> Information;
fn cached(&self) -> Information;
fn shared(&self) -> Information;
fn active(&self) -> Information;
fn inactive(&self) -> Information;
}
#[cfg(target_os = "linux")]
impl MemoryExt for Memory {
fn used(&self) -> Information {
let inner = self.as_ref();
let mut used = inner.total() - inner.free() - self.cached() - self.buffers();
if used <= Information::new::<information::byte>(0) {
used = inner.total() - inner.free()
}
used
}
fn buffers(&self) -> Information {
self.as_ref().buffers()
}
fn cached(&self) -> Information {
self.as_ref().cached()
}
fn shared(&self) -> Information {
self.as_ref().shared()
}
fn active(&self) -> Information {
self.as_ref().active()
}
fn inactive(&self) -> Information {
self.as_ref().inactive()
}
}