diff options
Diffstat (limited to 'src/fs.rs')
-rw-r--r-- | src/fs.rs | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/src/fs.rs b/src/fs.rs index 7dc94d3..831aa86 100644 --- a/src/fs.rs +++ b/src/fs.rs @@ -57,6 +57,18 @@ impl Webpath { pub fn as_dir(&self) -> String { format!("/{}/", self.webcanon) } + + /// Returns the first directory of the Webpath. Assumes the path is a + /// directory if it ends in a `/`, otherwise pops the last component. + pub fn first_dir(&self) -> String { + if self.is_dir { + self.webcanon.to_string() + } else { + let mut dir = self.webcanon.clone(); + dir.pop(); + dir.to_string() + } + } } impl Deref for Webpath { |