From a9e04b8ba2bd25eb0102ba42cf8c8d05e7d24250 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Tue, 21 Jun 2022 07:57:15 +0200 Subject: Relax interface of file helper functions This patch relaxes the interface of the file helper functions by allowing `impl AsRef` for creating file/directory pathes. This results in a less narrow interface, as now the functions can be used with Path, String, &str... Signed-off-by: Matthias Beyer --- crates/common/tedge_utils/src/file.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/crates/common/tedge_utils/src/file.rs b/crates/common/tedge_utils/src/file.rs index 1ca804f9..7fc1c1ab 100644 --- a/crates/common/tedge_utils/src/file.rs +++ b/crates/common/tedge_utils/src/file.rs @@ -34,29 +34,29 @@ pub enum FileError { } pub fn create_directory_with_user_group( - dir: &str, + dir: impl AsRef, user: &str, group: &str, mode: u32, ) -> Result<(), FileError> { let perm_entry = PermissionEntry::new(Some(user.into()), Some(group.into()), Some(mode)); - perm_entry.create_directory(Path::new(dir)) + perm_entry.create_directory(dir.as_ref()) } -pub fn create_directory_with_mode(dir: &str, mode: u32) -> Result<(), FileError> { +pub fn create_directory_with_mode(dir: impl AsRef, mode: u32) -> Result<(), FileError> { let perm_entry = PermissionEntry::new(None, None, Some(mode)); - perm_entry.create_directory(Path::new(dir)) + perm_entry.create_directory(dir.as_ref()) } pub fn create_file_with_user_group( - file: &str, + file: impl AsRef, user: &str, group: &str, mode: u32, default_content: Option<&str>, ) -> Result<(), FileError> { let perm_entry = PermissionEntry::new(Some(user.into()), Some(group.into()), Some(mode)); - perm_entry.create_file(Path::new(file), default_content) + perm_entry.create_file(file.as_ref(), default_content) } #[derive(Debug, PartialEq, Eq, Default, Clone)] -- cgit v1.2.3