summaryrefslogtreecommitdiffstats
path: root/src/files.rs
diff options
context:
space:
mode:
authorrabite <rabite@posteo.de>2019-03-09 11:06:13 +0100
committerrabite <rabite@posteo.de>2019-03-09 11:06:13 +0100
commit5d456539015876c1891bf0ac05b8f7dd3fbe8d57 (patch)
tree39e2e42cd28773eb9ac785d0430b51f72e6876d6 /src/files.rs
parent6e02ef6486b6660b69136e19c7086e8b2b3eb7ee (diff)
use enum to allow multiple widget types in hbox
Diffstat (limited to 'src/files.rs')
-rw-r--r--src/files.rs21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/files.rs b/src/files.rs
index fe0dc8b..daabb9e 100644
--- a/src/files.rs
+++ b/src/files.rs
@@ -3,6 +3,7 @@ use std::ops::Index;
use std::os::unix::fs::MetadataExt;
use std::path::{Path, PathBuf};
use std::sync::{Arc, Mutex};
+use std::hash::{Hash, Hasher};
use lscolors::LsColors;
use mime_detective;
@@ -294,6 +295,16 @@ impl PartialEq for File {
}
}
+impl Hash for File {
+ fn hash<H: Hasher>(&self, state: &mut H) {
+ self.name.hash(state);
+ self.path.hash(state);
+ self.selected.hash(state);
+ }
+}
+
+impl Eq for File {}
+
#[derive(Debug, Clone)]
pub struct File {
pub name: String,
@@ -403,6 +414,16 @@ impl File {
Some(mime.type_().as_str().to_string())
}
+
+ pub fn parent(&self) -> Option<PathBuf> {
+ Some(self.path.parent()?.to_path_buf())
+ }
+
+ pub fn parent_as_file(&self) -> HResult<File> {
+ let pathbuf = self.parent()?;
+ File::new_from_path(&pathbuf)
+ }
+
pub fn grand_parent(&self) -> Option<PathBuf> {
Some(self.path.parent()?.parent()?.to_path_buf())
}