diff options
author | hozan23 <hozan23@proton.me> | 2023-11-09 11:38:19 +0300 |
---|---|---|
committer | hozan23 <hozan23@proton.me> | 2023-11-09 11:38:19 +0300 |
commit | 849d827486c75b2ab223d7b0e638dbb5b74d4d1d (patch) | |
tree | 41cd3babc37147ec4a40cab8ce8ae31c91cce33b /karyons_core/src/utils/path.rs | |
parent | de1354525895ffbad18f90a5246fd65157f7449e (diff) |
rename crates
Diffstat (limited to 'karyons_core/src/utils/path.rs')
-rw-r--r-- | karyons_core/src/utils/path.rs | 39 |
1 files changed, 0 insertions, 39 deletions
diff --git a/karyons_core/src/utils/path.rs b/karyons_core/src/utils/path.rs deleted file mode 100644 index 2cd900a..0000000 --- a/karyons_core/src/utils/path.rs +++ /dev/null @@ -1,39 +0,0 @@ -use std::path::PathBuf; - -use crate::{error::Error, Result}; - -/// Returns the user's home directory as a `PathBuf`. -#[allow(dead_code)] -pub fn home_dir() -> Result<PathBuf> { - dirs::home_dir().ok_or(Error::PathNotFound("Home dir not found")) -} - -/// Expands a tilde (~) in a path and returns the expanded `PathBuf`. -#[allow(dead_code)] -pub fn tilde_expand(path: &str) -> Result<PathBuf> { - match path { - "~" => home_dir(), - p if p.starts_with("~/") => Ok(home_dir()?.join(&path[2..])), - _ => Ok(PathBuf::from(path)), - } -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn test_tilde_expand() { - let path = "~/src"; - let expanded_path = dirs::home_dir().unwrap().join("src"); - assert_eq!(tilde_expand(path).unwrap(), expanded_path); - - let path = "~"; - let expanded_path = dirs::home_dir().unwrap(); - assert_eq!(tilde_expand(path).unwrap(), expanded_path); - - let path = ""; - let expanded_path = PathBuf::from(""); - assert_eq!(tilde_expand(path).unwrap(), expanded_path); - } -} |