pub fn write_atomic(
path: impl AsRef<Path>,
write: impl FnOnce(&mut dyn Write) -> Result<()>,
) -> Result<()>Expand description
Write path atomically: stream through write into a temp file in the
same directory, then persist it over path in a single rename. A failed
or interrupted write leaves path untouched, so a concurrent reader never
observes a half-written file. Delegates the platform-specific atomic
replace to tempfile, which handles the Unix and Windows differences.
The temp file is a sibling of path so the rename stays within one
filesystem (a metadata move, not a copy). path must have a parent or be
relative to the current directory.