Skip to main content

base_scheduler/
file_options.rs

1// Released under the MIT License.
2// Copyright, 2026, by Samuel Williams.
3
4/// Portable regular-file opening options. Fields are visible to alternative implementations, including simulated filesystems. Append mode is omitted: positioned writes must target the supplied offset.
5#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
6pub struct FileOptions {
7    /// Open with read access.
8    pub read: bool,
9    /// Open with write access.
10    pub write: bool,
11    /// Create the file if it does not already exist. Requires `write`.
12    pub create: bool,
13    /// Create a new file, failing if one already exists at the path. Requires `write`, and takes precedence over `create` and `truncate`.
14    pub create_new: bool,
15    /// Truncate an existing file to zero length when opening it. Requires `write`.
16    pub truncate: bool,
17}
18
19impl FileOptions {
20    /// Open an existing file for reading only.
21    pub const READ: Self = Self {
22        read: true,
23        write: false,
24        create: false,
25        create_new: false,
26        truncate: false,
27    };
28    /// Open a file for writing only, creating it if missing and truncating it otherwise.
29    pub const CREATE: Self = Self {
30        read: false,
31        write: true,
32        create: true,
33        create_new: false,
34        truncate: true,
35    };
36}