1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
use std::path::PathBuf;

use async_trait::async_trait;
use serde::Serialize;
use shuttle_service::{Error, Factory, ResourceBuilder, Type};

#[derive(Serialize)]
pub struct StaticFolder<'a> {
    /// The folder to reach at runtime. Defaults to `static`
    folder: &'a str,
}

impl<'a> StaticFolder<'a> {
    pub fn folder(mut self, folder: &'a str) -> Self {
        self.folder = folder;

        self
    }
}

#[async_trait]
impl<'a> ResourceBuilder<PathBuf> for StaticFolder<'a> {
    const TYPE: Type = Type::StaticFolder;

    type Config = &'a str;

    type Output = PathBuf;

    fn new() -> Self {
        Self { folder: "static" }
    }

    fn config(&self) -> &&'a str {
        &self.folder
    }

    async fn output(self, _factory: &mut dyn Factory) -> Result<Self::Output, Error> {
        Ok(PathBuf::from(self.folder))
    }

    async fn build(build_data: &Self::Output) -> Result<PathBuf, Error> {
        Ok(build_data.clone())
    }
}