-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdisk.rs
More file actions
39 lines (36 loc) · 1.11 KB
/
disk.rs
File metadata and controls
39 lines (36 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
use serde::Serialize;
#[derive(Debug, Serialize)]
pub struct Disk {
pub name: String,
pub mount_point: String,
pub total_space: u64,
pub available_space: u64,
}
impl Disk {
#[tracing::instrument(name = "Disk::collect_all")]
pub fn collect_all() -> Vec<Self> {
let disks = sysinfo::Disks::new_with_refreshed_list();
if disks.list().is_empty() {
tracing::info!("no disks found");
}
disks.list().iter().map(Self::from).collect()
}
}
impl From<&sysinfo::Disk> for Disk {
fn from(sysinfo_disk: &sysinfo::Disk) -> Self {
let disk = Disk {
name: sysinfo_disk.name().to_string_lossy().into_owned(),
mount_point: sysinfo_disk.mount_point().to_string_lossy().into_owned(),
total_space: sysinfo_disk.total_space(),
available_space: sysinfo_disk.available_space(),
};
tracing::info!(
disk.mount_point,
disk.name,
disk.space.total = disk.total_space,
disk.space.available = disk.available_space,
"found disk"
);
disk
}
}