From 622887bcdc0bc457d5f58098041f01d8213efde8 Mon Sep 17 00:00:00 2001 From: Gwilym Inzani Date: Sat, 9 Mar 2024 12:09:34 +0000 Subject: [PATCH] Don't clone unnecessarily --- tools/src/utils.rs | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/tools/src/utils.rs b/tools/src/utils.rs index a9759165..7c5f99fe 100644 --- a/tools/src/utils.rs +++ b/tools/src/utils.rs @@ -1,19 +1,21 @@ -use std::{env, path::PathBuf}; +use std::{ + env, + path::{Path, PathBuf}, +}; #[derive(Debug)] pub struct FindRootDirectoryError; pub fn find_agb_root_directory() -> Result { - let mut current_path = env::current_dir().map_err(|_| FindRootDirectoryError)?; + let current_path = env::current_dir().map_err(|_| FindRootDirectoryError)?; - while !current_path.clone().join("justfile").exists() { - current_path = current_path - .parent() - .ok_or(FindRootDirectoryError)? - .to_owned(); + let mut search_path: &Path = ¤t_path; + + while !search_path.join("justfile").exists() { + search_path = search_path.parent().ok_or(FindRootDirectoryError)?; } - Ok(current_path) + Ok(search_path.to_owned()) } #[cfg(test)] @@ -22,6 +24,7 @@ mod tests { #[test] fn find_agb_root_directory_works() { - find_agb_root_directory().unwrap(); + let agb_root = find_agb_root_directory().unwrap(); + assert!(agb_root.join("justfile").exists()); } }