xdbm/src/storages.rs

60 lines
1.3 KiB
Rust
Raw Normal View History

//! Manipulates storages.
use clap::ValueEnum;
use physical_drive_partition::PhysicalDrivePartition;
use serde::{Deserialize, Serialize};
2023-08-29 04:22:04 +09:00
use std::fmt;
/// YAML file to store known storages..
pub const STORAGESFILE: &str = "storages.yml";
#[derive(ValueEnum, Clone, Copy, Debug)]
pub enum StorageType {
Physical,
// Online,
}
/// All storage types.
#[derive(Serialize, Deserialize, Debug)]
pub enum Storage {
PhysicalStorage(PhysicalDrivePartition),
// /// Online storage provided by others.
// OnlineStorage {
// name: String,
// provider: String,
// capacity: u8,
// },
}
impl Storage {
2023-08-29 21:33:46 +09:00
pub fn add_alias(&mut self, disk: &sysinfo::Disk, config_dir: &std::path::PathBuf) -> anyhow::Result<()> {
match self {
Self::PhysicalStorage(s) => s.add_alias(disk, config_dir),
}
}
}
impl StorageExt for Storage {
fn name(&self) -> &String {
match self {
Self::PhysicalStorage(s) => s.name(),
}
}
2023-08-29 21:33:46 +09:00
}
2023-08-29 04:22:04 +09:00
impl fmt::Display for Storage {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::PhysicalStorage(s) => s.fmt(f),
}
}
}
/// Trait to manipulate all `Storage`s (Enums).
pub trait StorageExt {
fn name(&self) -> &String;
}
pub mod physical_drive_partition;