From 6b3ff297656cf52017cf2e30120b0eda03d5fd24 Mon Sep 17 00:00:00 2001 From: Hector Castelli Zacharias Date: Fri, 5 Jan 2024 20:34:15 +0100 Subject: [PATCH] use path instead of pathbuf --- src/file_system.rs | 6 +++--- src/file_system/real_file_system.rs | 7 ++++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/file_system.rs b/src/file_system.rs index bf4884d..efe5ed2 100644 --- a/src/file_system.rs +++ b/src/file_system.rs @@ -1,11 +1,11 @@ -use std::path::PathBuf; +use std::path::{PathBuf, Path}; use mockall::automock; #[automock] pub(crate) trait FileSystem { - fn dir_exists(&self, path: &PathBuf) -> bool; - fn create_dir(&self, path: &PathBuf) -> Result; + fn dir_exists(&self, path: &Path) -> bool; + fn create_dir(&self, path: &Path) -> Result; } #[derive(Debug)] diff --git a/src/file_system/real_file_system.rs b/src/file_system/real_file_system.rs index d4ab6ec..266d389 100644 --- a/src/file_system/real_file_system.rs +++ b/src/file_system/real_file_system.rs @@ -4,6 +4,7 @@ use std::fs::create_dir_all; use std::fs::metadata; +use std::path::Path; use std::path::PathBuf; use super::FileSystem; @@ -11,13 +12,13 @@ use super::FileSystem; pub(crate) struct RealFileSystem; impl FileSystem for RealFileSystem { - fn dir_exists(&self, path: &PathBuf) -> bool { + fn dir_exists(&self, path: &Path) -> bool { metadata(path).map_or(false, |metadata| metadata.is_dir()) } - fn create_dir(&self, path: &PathBuf) -> Result { + fn create_dir(&self, path: &Path) -> Result { match create_dir_all(path) { - Ok(_) => Ok(path.clone()), + Ok(_) => Ok(PathBuf::from(path)), Err(_) => Err(FileSystemError::UnableToCreateDirectory), } }