pub struct OpenOptions<'s> { /* private fields */ }
Expand description

Options and flags which can be used to configure how a file is opened.

Implementations

Sets the option for read access.

This option, when true, will indicate that the file should be read-able if opened.

Sets the option for write access.

This option, when true, will indicate that the file should be write-able if opened.

If the file already exists, any write calls on it will overwrite its contents, without truncating it.

Sets the option for the append mode.

This option, when true, means that writes will append to a file instead of overwriting previous contents.

Note that setting .write(true).append(true) has the same effect as setting only .append(true).

For most filesystems, the operating system guarantees that all writes are atomic: no writes get mangled because another process writes at the same time.

Note that this function doesn’t create the file if it doesn’t exist. Use the OpenOptions::create method to do so.

Sets the option for truncating a previous file.

If a file is successfully opened with this option set it will truncate the file to 0 length if it already exists.

Only take effect if OpenOptions::create is set to true.

Sets the option to create a new file, or open it if it already exists.

Sets the option to create a new file, failing if it already exists.

No file is allowed to exist at the target location, also no (dangling) symlink.

In this way, if the call succeeds, the file returned is guaranteed to be new.

This option is useful because it is atomic.

Otherwise between checking whether a file exists and creating a new one, the file may have been created by another process (a TOCTOU race condition / attack).

If .create_new(true) is set, .create() and .truncate() are ignored.

Cancel Safety

This function is cancel safe.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.