我是否可以使用OpenOptions
或类似的单一方法来创建文件及其父目录并打开它?
这只会创建一个新文件,如果我的路径包括不存在的目录,则不起作用:
pub fn save_file(file_path: String) -> Result<(), Error> {
let mut db_file = OpenOptions::new()
.create(true)
.append(true)
.open(file_path)?;
db_file.write_all(b"some content")?;
Ok(())
}