Skip to main content

moirai_async/fs/
options.rs

1/// Configuration for file operations
2#[derive(Debug, Clone)]
3pub struct FileOpenOptions {
4    /// Open for reading
5    pub read: bool,
6    /// Open for writing
7    pub write: bool,
8    /// Create if not exists
9    pub create: bool,
10    /// Append mode
11    pub append: bool,
12    /// Truncate existing content
13    pub truncate: bool,
14}
15
16impl Default for FileOpenOptions {
17    fn default() -> Self {
18        Self {
19            read: true,
20            write: false,
21            create: false,
22            append: false,
23            truncate: false,
24        }
25    }
26}
27
28impl FileOpenOptions {
29    /// Create options for read-only access
30    pub fn read_only() -> Self {
31        Self {
32            read: true,
33            write: false,
34            create: false,
35            append: false,
36            truncate: false,
37        }
38    }
39
40    /// Create options for write-only access (creates if not exists)
41    pub fn write_only() -> Self {
42        Self {
43            read: false,
44            write: true,
45            create: true,
46            append: false,
47            truncate: true,
48        }
49    }
50
51    /// Create options for append access
52    pub fn append_only() -> Self {
53        Self {
54            read: false,
55            write: true,
56            create: true,
57            append: true,
58            truncate: false,
59        }
60    }
61
62    /// Create options for read-write access
63    pub fn read_write() -> Self {
64        Self {
65            read: true,
66            write: true,
67            create: true,
68            append: false,
69            truncate: false,
70        }
71    }
72}