| 130 | } |
| 131 | |
| 132 | fn open_mode_options(mode: &str) -> OpenOptions { |
| 133 | let mut options = OpenOptions::new(); |
| 134 | let plus = mode.as_bytes().contains(&b'+'); |
| 135 | |
| 136 | match mode.as_bytes().first().copied() { |
| 137 | Some(b'r') => { |
| 138 | options.read(true); |
| 139 | if plus { |
| 140 | options.write(true); |
| 141 | } |
| 142 | } |
| 143 | Some(b'w') => { |
| 144 | options.write(true).create(true).truncate(true); |
| 145 | if plus { |
| 146 | options.read(true); |
| 147 | } |
| 148 | } |
| 149 | Some(b'a') => { |
| 150 | options.write(true).create(true).append(true); |
| 151 | if plus { |
| 152 | options.read(true); |
| 153 | } |
| 154 | } |
| 155 | _ => { |
| 156 | options.read(true); |
| 157 | } |
| 158 | } |
| 159 | |
| 160 | options |
| 161 | } |
| 162 | } |
| 163 | |
| 164 | fn build_imports(store: &mut Store, state: Rc<RefCell<HostState>>) -> Imports { |