pub fn write_file<P>(dst: P, data: &[u8]) -> Result<()>Expand description
§Atomic File Write!
Write content to a file, atomically.
Under the hood, this method creates a temporary file to hold all the changes, then moves that file into place once everything is good to go.
If a file already exists at the destination path, this method will (try to) preserve its permissions and ownership.
If not, it will simply create it.
Unlike File::create, this method will also
attempt to create any missing parent directories.
§Examples
// It's just one line:
match write_atomic::write_file("/path/to/my/file.txt", b"Some data!") {
// The file was saved!
Ok(()) => {},
// There was an std::io::Error.
Err(e) => panic!("{e}"),
};§Errors
This will bubble up any filesystem-related errors encountered along the way.