add: Debug for storages

This commit is contained in:
qwjyh 2023-08-29 04:22:04 +09:00
parent 092809c2c6
commit ae9cd0ee4c
3 changed files with 66 additions and 30 deletions

View file

@ -3,8 +3,12 @@
use crate::devices::Device;
use crate::storages::StorageExt;
use anyhow::{Context, Result};
use byte_unit::Byte;
use serde::{Deserialize, Serialize};
use std::collections::{hash_map::RandomState, HashMap};
use std::{
collections::{hash_map::RandomState, HashMap},
fmt,
};
use sysinfo::DiskExt;
/// Partitoin of physical (on-premises) drive.
@ -73,3 +77,19 @@ impl StorageExt for PhysicalDrivePartition {
&self.name
}
}
impl fmt::Display for PhysicalDrivePartition {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let removable_indicator = if self.is_removable { "+" } else { "-" };
write!(
f,
"{name:<10} {size} {removable:<1} {kind:<6} {fs:<5}",
name = self.name(),
size = Byte::from_bytes(self.capacity.into()).get_appropriate_unit(true),
removable = removable_indicator,
kind = self.kind,
fs = self.fs,
// path = self. TODO: display path or contain it in struct
)
}
}