mirror of
https://github.com/ouch-org/ouch.git
synced 2025-06-07 12:05:46 +00:00
Optimize strip_cur_dir
(#167)
This commit is contained in:
parent
739a52f00e
commit
43fb274956
@ -30,11 +30,8 @@ pub fn create_dir_if_non_existent(path: &Path) -> crate::Result<()> {
|
|||||||
/// Removes the current dir from the beginning of a path
|
/// Removes the current dir from the beginning of a path
|
||||||
/// normally used for presentation sake.
|
/// normally used for presentation sake.
|
||||||
/// If this function fails, it will return source path as a PathBuf.
|
/// If this function fails, it will return source path as a PathBuf.
|
||||||
pub fn strip_cur_dir(source_path: &Path) -> PathBuf {
|
pub fn strip_cur_dir(source_path: &Path) -> &Path {
|
||||||
source_path
|
source_path.strip_prefix(Component::CurDir).unwrap_or(source_path)
|
||||||
.strip_prefix(Component::CurDir)
|
|
||||||
.map(|path| path.to_path_buf())
|
|
||||||
.unwrap_or_else(|_| source_path.to_path_buf())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns current directory, but before change the process' directory to the
|
/// Returns current directory, but before change the process' directory to the
|
||||||
|
Loading…
x
Reference in New Issue
Block a user