Expand description
Replace a file atomically.
The new bytes go to a sibling temp file that is renamed over the target, so a reader, a crash or a full disk never sees a half-written file: the target holds either the old bytes or the new ones.
use std::io::Write;
atomic_replace::write("state.json", b"{}\n")?;
atomic_replace::Options::new()
.create_parent(true)
.durable(false)
.write_with("cache/index.bin", |file| file.write_all(b"index"))?;Structs§
- Options
- How
Options::writeandOptions::write_withreplace a file.