crud_file_server/
state.rs

1use crate::Config;
2use async_std::path::PathBuf;
3use async_std::{fs, io};
4
5pub struct State {
6    pub dir_path: PathBuf,
7}
8
9impl State {
10    pub async fn from_config(config: Config) -> io::Result<Self> {
11        let Config { dir_path, .. } = config;
12        if !dir_path.is_dir().await {
13            fs::create_dir_all(&dir_path).await?;
14        }
15        Ok(Self { dir_path })
16    }
17}