1个不稳定版本
0.1.0 | 2023年8月29日 |
---|
#563 在 操作系统
7KB
52 行
扩展PathBuf
以下是一些使用示例
let path = Path::new("C:\\Users\\user\\Desktop\\test.txt");
let path = path.replace("user/Desktop", "user/Documents");
assert_eq!(path, PathBuf::from("C:\\Users\\user\\Documents\\test.txt"));
let path = Path::new("C:\\Users\\user\\Desktop\\test.txt");
assert!(path.contains("Desktop"));
assert!(!path.contains("Documents"));
// Windows
assert!(path.contains("user\\Desktop"));
assert!(!path.contains("user\\Documents"));
// Linux
assert!(path.contains("user/Desktop"));
assert!(!path.contains("user/Documents"));