Function write_atomic::write_file [−][src]
pub fn write_file<P>(src: P, data: &[u8]) -> Result<()> where
P: AsRef<Path>,
Expand description
Atomic File Write!
This will write bytes atomically to the specified path, maintaining
permissions and ownership if it already exists, or creating it anew using
the same default permissions and ownership std::fs::File::create
would.
Atomicity is achieved by first writing the content to a temporary location.
On most Linux systems, this will use O_TMPFILE
; for other systems, the
tempfile
crate will be used instead.
Examples
// It's just one line: write_atomic::write_file("/path/to/my/file.txt", b"Some data!") .unwrap();
Errors
This will bubble up any filesystem-related errors encountered along the way.