#[non_exhaustive]pub enum OpenOptionsWriteMode {
None,
Write,
Append,
}Expand description
Controls the way writes to an opened file are performed. Write modes do not affect how the file is opened - creating the file or truncating it require separate options.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
None
No writing permitted. Allows opening files where the process lacks write permissions, and attempts to write will fail.
Write
Writes permitted. The file location pointer tracked by the OS determines where writes in the file will take place.
Append
Writes permitted. The OS will place each write at the current end of the
file. These may still change the file location pointer, so if reads are
being used as well, be sure to seek to the desired location before
reading. One way to do this is to use seek to save the file location
pointer (seek(SeekFrom::Current(0))) and then apply the result before
the next read.
Most OSes and filesystems make these writes atomically, such that different threads or even processes can collaborate safely on a single file, as long as each write call provides a full unit of data (e.g. a line, or a binary struct etc). This can be done by building up the data to write, or using a buffered writer that is large enough and calling flush after each unit is complete.
In particular NFS on Linux is documented as not providing atomic appends.
use std::fs::OpenOptions;
let file = OpenOptions::new().write(OpenOptionsWriteMode::Append).open_at(&mut parent, "foo.txt");Trait Implementations§
Source§impl Clone for OpenOptionsWriteMode
impl Clone for OpenOptionsWriteMode
Source§fn clone(&self) -> OpenOptionsWriteMode
fn clone(&self) -> OpenOptionsWriteMode
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more