Skip to content

Commit

Permalink
Return Path from strip_prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
jelmer committed Sep 23, 2024
1 parent bc74692 commit 950e48e
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,13 @@ pub mod patch;
pub mod quilt;
pub mod timestamp;

// TODO: Return a Path instead of a PathBuf
/// Strip the specified number of path components from the beginning of the path.
pub fn strip_prefix(path: &std::path::Path, prefix: usize) -> std::path::PathBuf {
path.components().skip(prefix).collect()
pub fn strip_prefix(path: &std::path::Path, prefix: usize) -> &std::path::Path {
let mut components = path.components();
for _ in 0..prefix {
components.next();
}
std::path::Path::new(components.as_path())
}

#[test]
Expand Down

0 comments on commit 950e48e

Please sign in to comment.