use crate::symbols::Symbol; use async_trait::async_trait; use std::error::Error; use std::fs; use std::io; use std::path::Path; #[derive(Debug)] pub struct Dir

{ path: P, } impl

Dir

{ pub fn new(path: P) -> Self { Self { path } } } #[async_trait(?Send)] impl> Symbol for Dir

{ async fn target_reached(&self) -> Result> { if !self.path.as_ref().exists() { return Ok(false); } let metadata = fs::metadata(self.path.as_ref())?; if !metadata.is_dir() { return Err(Box::new(io::Error::new( io::ErrorKind::AlreadyExists, "Could not create a directory, non-directory file exists", ))); } Ok(true) } async fn execute(&self) -> Result<(), Box> { fs::create_dir(self.path.as_ref()).map_err(|e| Box::new(e) as Box) } }