refactor(rust): cleanup path handling

- Avoids unnecessary string allocation when tracing paths
- Replaces `mut path & path.push()` with `path.join()`
- Avoids unncessary cloning of paths where applicable
- Use `dunce` crate to remove `UNC` prefix
- Improve performance of resolving `~` by avoiding unnecessary string allocations
- Resolve `~`, `$Env:USERPROFILE` and `$HOME` consistenly between different code paths
- Use `PathBuf` instead of `String` for paths in CLI args

I may have missed a couple of places but I think I covered 90% of path handling in the codebase
This commit is contained in:
amrbashir
2023-11-25 09:14:54 +02:00
committed by LGUG2Z
parent a68f3843b7
commit b39e65642b
18 changed files with 305 additions and 530 deletions
Generated
+9
View File
@@ -328,6 +328,12 @@ dependencies = [
"windows-sys 0.48.0",
]
[[package]]
name = "dunce"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "56ce8c6da7551ec6c462cbaf3bfbc75131ebbfa1c944aeaa9dab51ca1c5f0c3b"
[[package]]
name = "dyn-clone"
version = "1.0.16"
@@ -824,6 +830,8 @@ version = "0.1.19"
dependencies = [
"clap",
"color-eyre",
"dirs",
"dunce",
"schemars",
"serde",
"serde_json",
@@ -840,6 +848,7 @@ dependencies = [
"color-eyre",
"derive-ahk",
"dirs",
"dunce",
"fs-tail",
"heck",
"komorebi-core",