use crate::errors::{Error, ErrorKind};
use std::io;
use std::path::Path;
#[derive(Debug, Default)]
#[cfg_attr(docsrs, doc(cfg(feature = "tokio")))]
pub struct DirBuilder {
inner: tokio::fs::DirBuilder,
}
impl DirBuilder {
pub fn new() -> Self {
Default::default()
}
pub fn recursive(&mut self, recursive: bool) -> &mut Self {
self.inner.recursive(recursive);
self
}
pub async fn create(&self, path: impl AsRef<Path>) -> io::Result<()> {
let path = path.as_ref();
self.inner
.create(path)
.await
.map_err(|err| Error::build(err, ErrorKind::CreateDir, path))
}
}
#[cfg(unix)]
impl DirBuilder {
pub fn mode(&mut self, mode: u32) -> &mut Self {
self.inner.mode(mode);
self
}
}