rocket-include-static-resources 0.10.5

This is a crate which provides macros `static_resources_initializer!` and `static_response_handler!` to statically include files from your Rust project and make them be the HTTP response sources quickly.
Documentation
use super::{StaticContextManager, StaticResources, StaticResponse};
use crate::rocket::{
    fairing::{Fairing, Info, Kind},
    Build, Rocket,
};

const FAIRING_NAME: &str = "Static Resources";

/// The fairing of `StaticResponse`.
pub struct StaticResponseFairing {
    pub(crate) custom_callback: Box<dyn Fn(&mut StaticResources) + Send + Sync + 'static>,
}

#[rocket::async_trait]
impl Fairing for StaticResponseFairing {
    #[inline]
    fn info(&self) -> Info {
        Info {
            name: FAIRING_NAME, kind: Kind::Ignite
        }
    }

    #[inline]
    async fn on_ignite(&self, rocket: Rocket<Build>) -> Result<Rocket<Build>, Rocket<Build>> {
        let mut resources = StaticResources::new();

        (self.custom_callback)(&mut resources);

        let state = StaticContextManager::new(resources);

        Ok(rocket.manage(state))
    }
}

impl StaticResponse {
    #[inline]
    /// Create the fairing of `HandlebarsResponse`.
    pub fn fairing<F>(f: F) -> impl Fairing
    where
        F: Fn(&mut StaticResources) + Send + Sync + 'static, {
        StaticResponseFairing {
            custom_callback: Box::new(f)
        }
    }
}