1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
use std::{fs, io, path::PathBuf};
#[derive(Clone, Debug)]
pub struct OpenOptions(fs::OpenOptions);
impl OpenOptions {
pub fn new() -> Self {
OpenOptions(fs::OpenOptions::new())
}
pub fn read(&mut self, read: bool) -> &mut Self {
self.0.read(read);
self
}
pub fn write(&mut self, write: bool) -> &mut Self {
self.0.write(write);
self
}
pub fn append(&mut self, append: bool) -> &mut Self {
self.0.append(append);
self
}
pub fn truncate(&mut self, truncate: bool) -> &mut Self {
self.0.truncate(truncate);
self
}
pub fn create(&mut self, create: bool) -> &mut Self {
self.0.create(create);
self
}
pub fn create_new(&mut self, create_new: bool) -> &mut Self {
self.0.create_new(create_new);
self
}
pub fn open<P>(&self, path: P) -> io::Result<crate::File>
where
P: Into<PathBuf>,
{
#[allow(deprecated)]
crate::File::from_options(path.into(), self.options())
}
}
impl OpenOptions {
pub fn from_options(options: fs::OpenOptions) -> Self {
Self(options)
}
pub fn options(&self) -> &fs::OpenOptions {
&self.0
}
pub fn options_mut(&mut self) -> &mut fs::OpenOptions {
&mut self.0
}
}
#[cfg(unix)]
mod unix {
use crate::os::unix::fs::OpenOptionsExt;
use std::os::unix::fs::OpenOptionsExt as _;
impl OpenOptionsExt for crate::OpenOptions {
fn mode(&mut self, mode: u32) -> &mut Self {
self.options_mut().mode(mode);
self
}
fn custom_flags(&mut self, flags: i32) -> &mut Self {
self.options_mut().custom_flags(flags);
self
}
}
}
#[cfg(windows)]
mod windows {
use crate::os::windows::fs::OpenOptionsExt;
use std::os::windows::fs::OpenOptionsExt as _;
impl OpenOptionsExt for crate::OpenOptions {
fn access_mode(&mut self, access: u32) -> &mut Self {
self.options_mut().access_mode(access);
self
}
fn share_mode(&mut self, val: u32) -> &mut Self {
self.options_mut().share_mode(val);
self
}
fn custom_flags(&mut self, flags: u32) -> &mut Self {
self.options_mut().custom_flags(flags);
self
}
fn attributes(&mut self, val: u32) -> &mut Self {
self.options_mut().attributes(val);
self
}
fn security_qos_flags(&mut self, flags: u32) -> &mut Self {
self.options_mut().security_qos_flags(flags);
self
}
}
}