From 71e3cad6dabb0db9116acfc7dfd9457906117bb3 Mon Sep 17 00:00:00 2001 From: qwjyh Date: Sat, 24 Feb 2024 18:31:56 +0900 Subject: [PATCH] new: method for storage list --- README.md | 1 + src/main.rs | 1 + src/storages.rs | 20 +++++++++++++++++++- 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 07b1df8..350efb7 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,4 @@ # TODO: +- [ ] split subcommands to functions - [ ] reorganize cmd option for storage - [ ] use subcommand diff --git a/src/main.rs b/src/main.rs index 65c5a7e..ca1b9d3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -373,6 +373,7 @@ fn main() -> Result<()> { for (k, storage) in &storages { println!("{}: {}", k, storage); println!(" {}", storage.mount_path(&device, &storages)?.display()); + // println!("{}: {}", storage.shorttypename(), storage.name()); // TODO } } StorageCommands::Bind { diff --git a/src/storages.rs b/src/storages.rs index 912e632..7e3ece6 100644 --- a/src/storages.rs +++ b/src/storages.rs @@ -27,7 +27,25 @@ pub enum Storage { Online(OnlineStorage), } -impl Storage {} +impl Storage { + /// Full type name like "PhysicalStorage". + pub fn typename(&self) -> &str { + match self { + Self::PhysicalStorage(_) => "PhysicalStorage", + Self::SubDirectory(_) => "SubDirectory", + Self::Online(_) => "OnlineStorage", + } + } + + /// Short type name with one letter like "P". + pub fn shorttypename(&self) -> &str { + match self { + Self::PhysicalStorage(_) => "P", + Self::SubDirectory(_) => "S", + Self::Online(_) => "O", + } + } +} impl StorageExt for Storage { fn name(&self) -> &String {