Function bczhc_lib::fs::new_unique_file
source · pub fn new_unique_file<P>(path: P) -> Result<PathBuf>where
P: AsRef<Path>,Expand description
create a file with unique filename for preventing from overwriting existing files
Examples
use std::path::Path;
use bczhc_lib::fs::new_unique_file;
let path = Path::new("~/hello");
// now `path` doesn't exist; return without any changes
assert_eq!(new_unique_file(path).unwrap().as_path(), path);
let new_path = new_unique_file(path);
// the new path contains ".1" suffix
assert_eq!(new_path.unwrap().as_path(), Path::new("~/hello.1"))