tokio_fs_ext/fs/native/
open_options.rs1use std::{io, path::Path};
2
3use crate::fs::File;
4
5pub struct OpenOptions(tokio::fs::OpenOptions);
6
7impl OpenOptions {
8 pub fn new() -> OpenOptions {
9 OpenOptions(tokio::fs::OpenOptions::new())
10 }
11
12 pub fn read(&mut self, read: bool) -> &mut OpenOptions {
13 self.0.read(read);
14 self
15 }
16
17 pub fn write(&mut self, write: bool) -> &mut OpenOptions {
18 self.0.write(write);
19 self
20 }
21
22 pub fn append(&mut self, append: bool) -> &mut OpenOptions {
23 self.0.append(append);
24 self
25 }
26
27 pub fn truncate(&mut self, truncate: bool) -> &mut OpenOptions {
28 self.0.truncate(truncate);
29 self
30 }
31
32 pub fn create(&mut self, create: bool) -> &mut OpenOptions {
33 self.0.create(create);
34 self
35 }
36
37 pub fn create_new(&mut self, create_new: bool) -> &mut OpenOptions {
38 self.0.create_new(create_new);
39 self
40 }
41
42 pub async fn open(&self, path: impl AsRef<Path>) -> io::Result<File> {
43 let inner = self.0.open(path).await?;
44 Ok(File {
45 inner,
46 seek_pos: None,
47 })
48 }
49}
50
51impl Default for OpenOptions {
52 fn default() -> Self {
53 Self::new()
54 }
55}