Skip to main content

write_string_atomic

Function write_string_atomic 

Source
pub fn write_string_atomic(path: &Path, contents: &str) -> Result<()>
Expand description

Writes contents to path via a uniquely-named temp file then renames it into place. On Unix the rename is atomic, the file is created 0600, and the parent directory is best-effort restricted to 0700. On Windows the rename replaces an existing destination but is not crash-atomic.

Blocking: this function uses synchronous filesystem I/O. Call it from within tokio::task::spawn_blocking when used in an async context to avoid stalling the executor.

ยงErrors

Returns an error when the directory cannot be created or the write/rename fails.