#replace #pathbuf #string #contain

pathbuf-ext

Extends PathBuf to handle replace and contains string methods

1 unstable release

0.1.0 Aug 29, 2023

#577 in Operating systems

MIT license

7KB
52 lines

Extended PathBuf

Here are some examples on how to use it:

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"));

No runtime deps