1 /// @brief 切分路径字符串,返回最左侧那一级的目录名和剩余的部分。 2 /// 3 /// 举例:对于 /123/456/789/ 本函数返回的第一个值为123, 第二个值为456/789 4 pub fn split_path(path: &str) -> (&str, Option<&str>) { 5 let mut path_split: core::str::SplitN<&str> = path.trim_matches('/').splitn(2, "/"); 6 let comp = path_split.next().unwrap_or(""); 7 let rest_opt = path_split.next(); 8 9 return (comp, rest_opt); 10 } 11 12 /// @brief 切分路径字符串,返回最右侧那一级的目录名和剩余的部分。 13 /// 14 /// 举例:对于 /123/456/789/ 本函数返回的第一个值为789, 第二个值为123/456 15 pub fn rsplit_path(path: &str) -> (&str, Option<&str>) { 16 let mut path_split: core::str::RSplitN<&str> = path.trim_matches('/').rsplitn(2, "/"); 17 let comp = path_split.next().unwrap_or(""); 18 let rest_opt = path_split.next(); 19 20 return (comp, rest_opt); 21 } 22