(WIP) implementing storage::directory

This commit is contained in:
qwjyh 2023-09-01 10:37:30 +09:00
parent 33e1a9aba7
commit 1f0e43cd52
4 changed files with 68 additions and 6 deletions

49
src/storages/directory.rs Normal file
View file

@ -0,0 +1,49 @@
//! Manipulate subdirectories of other storages, including directories.
use serde::{Deserialize, Serialize};
use std::{path, fmt::{self, write}, rc::Rc};
use super::{Storage, StorageExt};
/// Subdirectory of other [Storage]s.
#[derive(Serialize, Deserialize, Debug)]
pub struct Directory {
name: String,
parent: Box<Storage>,
relative_path: path::PathBuf,
notes: String,
}
impl Directory {
/// - `name`: id
/// - `parent`: where the directory locates.
/// - `relative_path`: path from root of the parent storage.
/// - `notes`: supplimental notes.
pub fn new(
name: String,
parent: Rc<Storage>, // todo implement serialize
relative_path: path::PathBuf,
notes: String,
) -> Directory {
Directory {name, parent, relative_path, notes}
}
}
impl StorageExt for Directory {
fn name(&self) -> &String {
&self.name
}
}
impl fmt::Display for Directory {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
"S {name:<10} < {parent:<10}{relative_path:<10} : {notes}",
name = self.name(),
parent = self.parent,
relative_path = self.relative_path.display(),
notes = self.notes,
)
}
}

View file

@ -80,7 +80,7 @@ impl fmt::Display for PhysicalDrivePartition {
let removable_indicator = if self.is_removable { "+" } else { "-" };
write!(
f,
"{name:<10} {size} {removable:<1} {kind:<6} {fs:<5}",
"P {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,