From 03915c3d33a6a053a1455a2ba48ad57e0477365a Mon Sep 17 00:00:00 2001 From: cyqsimon <28627918+cyqsimon@users.noreply.github.com> Date: Thu, 23 Mar 2023 07:39:00 +0800 Subject: Make file util functions generic --- src/file_utils.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/file_utils.rs b/src/file_utils.rs index fdd68ba..ba976de 100644 --- a/src/file_utils.rs +++ b/src/file_utils.rs @@ -4,10 +4,10 @@ use std::path::{Component, Path, PathBuf}; /// and optionally prevent traversing hidden directories. /// /// See the unit tests tests::test_sanitize_path* for examples -pub fn sanitize_path(path: &Path, traverse_hidden: bool) -> Option { +pub fn sanitize_path(path: impl AsRef, traverse_hidden: bool) -> Option { let mut buf = PathBuf::new(); - for comp in path.components() { + for comp in path.as_ref().components() { match comp { Component::Normal(name) => buf.push(name), Component::ParentDir => { @@ -30,9 +30,9 @@ pub fn sanitize_path(path: &Path, traverse_hidden: bool) -> Option { } /// Returns if a path goes through a symbolic link -pub fn contains_symlink(path: &PathBuf) -> bool { +pub fn contains_symlink(path: impl AsRef) -> bool { let mut joined_path = PathBuf::new(); - for path_slice in path { + for path_slice in path.as_ref().iter() { joined_path = joined_path.join(path_slice); if !joined_path.exists() { // On Windows, `\\?\` won't exist even though it's the root -- cgit v1.2.3