mirror of
https://github.com/qwjyh/xdbm
synced 2025-07-07 07:09:19 +09:00
(WIP) implementing storage::directory
This commit is contained in:
parent
33e1a9aba7
commit
1f0e43cd52
4 changed files with 68 additions and 6 deletions
49
src/storages/directory.rs
Normal file
49
src/storages/directory.rs
Normal 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,
|
||||
)
|
||||
}
|
||||
}
|
|
@ -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,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue