From b341cbc25d4294be97381e6328bca198bbe881c5 Mon Sep 17 00:00:00 2001 From: Ellis Clayton Date: Sat, 2 May 2026 09:01:28 +1000 Subject: [PATCH] Swap home path to Path No mutation happening, so there's no need for it to be a PathBuf. --- src/config.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/config.rs b/src/config.rs index c836c95..89c5d8f 100644 --- a/src/config.rs +++ b/src/config.rs @@ -592,7 +592,7 @@ impl<'a> Config<'a> { } } else if let Some(config_value) = &raw_config.directories.cache_dir { // Resolve possible ~ prefixed path - let expanded_path = expand_home(config_value, home_path.as_ref())?; + let expanded_path = expand_home(config_value, home_path.as_deref())?; // Resolve possible relative path. let resolved_path = relative_path_root.join(expanded_path); @@ -616,7 +616,7 @@ impl<'a> Config<'a> { .as_ref() .map(|path| -> Result { // Resolve possible ~ prefixed path - let expanded_path = expand_home(path, home_path.as_ref())?; + let expanded_path = expand_home(path, home_path.as_deref())?; // Resolve possible relative path. let resolved_path = relative_path_root.join(expanded_path); @@ -654,7 +654,7 @@ impl<'a> Config<'a> { } /// Expands tilde (~) prefixed directories into its absolute version -fn expand_home<'a>(input_path: &'a Path, home_path: Option<&PathBuf>) -> Result> { +fn expand_home<'a>(input_path: &'a Path, home_path: Option<&Path>) -> Result> { let mut components = input_path.components(); if let Some(Component::Normal(first_component_raw)) = components.next() { @@ -830,7 +830,7 @@ mod test { let path_to_expand = PathBuf::from("~/baz"); assert_eq!( - *expand_home(&path_to_expand, home.as_ref()).unwrap(), + *expand_home(&path_to_expand, home.as_deref()).unwrap(), PathBuf::from("/foo/bar/baz") ); } @@ -841,7 +841,7 @@ mod test { let dir_to_expand = PathBuf::from("/one/two"); assert_eq!( - *expand_home(&dir_to_expand, home.as_ref()).unwrap(), + *expand_home(&dir_to_expand, home.as_deref()).unwrap(), dir_to_expand ); } @@ -851,7 +851,7 @@ mod test { let home = Some(PathBuf::from("/foo/bar")); let dir_to_expand = PathBuf::from("~baz/foo"); - assert!(expand_home(&dir_to_expand, home.as_ref()).is_err()); + assert!(expand_home(&dir_to_expand, home.as_deref()).is_err()); } #[test]