diff options
author | qkzk <qu3nt1n@gmail.com> | 2022-12-16 00:02:04 +0100 |
---|---|---|
committer | qkzk <qu3nt1n@gmail.com> | 2022-12-16 00:02:04 +0100 |
commit | b43cbc1ba788674fadc3e3b8244aa25e2626675b (patch) | |
tree | 8e57235fe6f527a5be051c4f1558a8f5399b32d5 /src/marks.rs | |
parent | 8f59ffdc608b913cedf870e8b5c9418707303020 (diff) |
massive documentaion and some refactoring.
Diffstat (limited to 'src/marks.rs')
-rw-r--r-- | src/marks.rs | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/src/marks.rs b/src/marks.rs index 5963b58..ef6b811 100644 --- a/src/marks.rs +++ b/src/marks.rs @@ -7,12 +7,17 @@ use crate::fm_error::{ErrorVariant, FmError, FmResult}; static MARKS_FILEPATH: &str = "~/.config/fm/marks.cfg"; +/// Holds the marks created by the user. +/// It's a map between any char (except :) and a PathBuf. pub struct Marks { save_path: PathBuf, marks: HashMap<char, PathBuf>, } impl Marks { + /// Reads the marks stored in the config file (~/.config/fm/marks.cfg). + /// If an invalid marks is read, only the valid ones are kept + /// and the file is saved again. pub fn read_from_config_file() -> Self { let path = PathBuf::from(shellexpand::tilde(&MARKS_FILEPATH).to_string()); Self::read_from_file(path) @@ -38,6 +43,7 @@ impl Marks { marks } + /// Returns an optional marks associated to a char bind. pub fn get(&self, ch: char) -> Option<&PathBuf> { self.marks.get(&ch) } @@ -62,6 +68,8 @@ impl Marks { } } + /// Store a new mark in the config file. + /// All the marks are saved again. pub fn new_mark(&mut self, ch: char, path: PathBuf) -> FmResult<()> { if ch == ':' { return Err(FmError::new( @@ -94,6 +102,7 @@ impl Marks { .to_owned()) } + /// Returns a vector of strings like "d: /dev" for every mark. pub fn as_strings(&self) -> Vec<String> { self.marks .iter() |