rustftechh 0.1.1

A blazingly fast, highly extensible, and feature-rich system information tool written in Rust with fastfetch parity and multi-distro logos
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
use super::ffi;
use crate::info::platform::format_usage_gib;

pub fn detect_swap() -> Option<String> {
    unsafe {
        let mut status = ffi::MEMORYSTATUSEX::zeroed();
        if ffi::GlobalMemoryStatusEx(&mut status) == 0 {
            return None;
        }
        let total = status.ullTotalPageFile.saturating_sub(status.ullTotalPhys);
        let avail = status.ullAvailPageFile.saturating_sub(status.ullAvailPhys);
        if total == 0 {
            return Some("Disabled".into());
        }
        let used = total.saturating_sub(avail.min(total));
        format_usage_gib(used, total)
    }
}