1 use std::path::PathBuf; 2 3 use anyhow::{anyhow, Result}; 4 5 /// 检查目录是否存在 6 pub(super) fn check_dir_exists<'a>(path: &'a PathBuf) -> Result<&'a PathBuf> { 7 if !path.exists() { 8 return Err(anyhow!("Path '{}' not exists", path.display())); 9 } 10 if !path.is_dir() { 11 return Err(anyhow!("Path '{}' is not a directory", path.display())); 12 } 13 14 return Ok(path); 15 } 16 17 /// 获取给定路径的绝对路径 18 pub fn abs_path(path: &PathBuf) -> PathBuf { 19 if path.is_absolute() { 20 path.to_path_buf() 21 } else { 22 std::env::current_dir().unwrap().join(path) 23 } 24 } 25