tokio_fs_ext/fs/wasm/
dir_builder.rs

1use std::{io, path::Path};
2
3use super::{create_dir, create_dir_all};
4
5#[derive(Debug, Default)]
6pub struct DirBuilder {
7    recursive: bool,
8}
9
10impl DirBuilder {
11    pub fn new() -> Self {
12        DirBuilder::default()
13    }
14
15    pub fn recursive(&mut self, recursive: bool) -> &mut Self {
16        self.recursive = recursive;
17        self
18    }
19
20    pub async fn create(&self, path: impl AsRef<Path>) -> io::Result<()> {
21        if self.recursive {
22            create_dir_all(path).await?;
23        } else {
24            create_dir(path).await?;
25        }
26        Ok(())
27    }
28}