Skip to content

Commit

Permalink
feat(VfsPath): Add VfsPath::root() method
Browse files Browse the repository at this point in the history
  • Loading branch information
manuel-woelker committed Mar 6, 2022
1 parent 45b55b5 commit 5afee4e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,23 @@ impl VfsPath {
})
}

/// Returns the root path of this filesystem
///
/// ```
/// # use vfs::{MemoryFS, VfsError, VfsFileType, VfsPath};
/// let path = VfsPath::new(MemoryFS::new());
/// let directory = path.join("foo/bar")?;
///
/// assert_eq!(directory.root(), path);
/// # Ok::<(), VfsError>(())
/// ```
pub fn root(&self) -> VfsPath {
VfsPath {
path: "".to_string(),
fs: self.fs.clone(),
}
}

/// Creates the directory at this path
///
/// Note that the parent directory must exist.
Expand Down
7 changes: 7 additions & 0 deletions src/test_macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1019,6 +1019,13 @@ macro_rules! test_vfs_readonly {
);
}

#[test]
fn root() {
let root = create_root();
assert_eq!(root, root.root());
assert_eq!(root.join("foo/bar").unwrap().root(), root.root());
}

#[test]
fn eq() {
let root = create_root();
Expand Down

0 comments on commit 5afee4e

Please sign in to comment.