31 lines
643 B
Rust
31 lines
643 B
Rust
use sysinfo::System;
|
|
|
|
/// A struct to hold system resource information.
|
|
pub struct Resources {
|
|
/// Total memory in megabytes.
|
|
pub total_memory_mb: u64,
|
|
/// Number of CPU cores.
|
|
pub cpu_cores: usize,
|
|
}
|
|
|
|
impl Resources {
|
|
/// Detects the system's resources.
|
|
pub fn new() -> Self {
|
|
let mut sys = System::new();
|
|
sys.refresh_all();
|
|
|
|
let total_memory_mb = sys.total_memory() / 1024 / 1024;
|
|
let cpu_cores = sys.cpus().len();
|
|
|
|
Self {
|
|
total_memory_mb,
|
|
cpu_cores,
|
|
}
|
|
}
|
|
}
|
|
|
|
impl Default for Resources {
|
|
fn default() -> Self {
|
|
Self::new()
|
|
}
|
|
} |