roadster 0.9.0-alpha.6

A "Batteries Included" web framework for rust designed to get you moving fast.
Documentation
pub mod any;
pub mod default;
pub mod normalize_path;

use crate::app::context::AppContext;
use axum::Router;
use axum_core::extract::FromRef;

/// Provides hooks into various stages of the app's startup to allow initializing and installing
/// anything that needs to be done during a specific stage of startup of the HTTP service.
#[cfg_attr(test, mockall::automock(type Error = crate::error::Error;))]
pub trait Initializer<S>: Send
where
    S: 'static + Send + Sync + Clone,
    AppContext: FromRef<S>,
{
    type Error: Send + Sync + std::error::Error;

    fn name(&self) -> String;

    fn enabled(&self, state: &S) -> bool;

    /// Used to determine the order in which the initializer will run during app initialization.
    /// Smaller numbers will run before larger numbers. For example, an initializer with priority
    /// `-10` will run before an initializer with priority `10`.
    ///
    /// If two initializers have the same priority, they are not guaranteed to run in any particular
    /// order relative to each other. This may be fine for many initializers.
    ///
    /// If the order in which your initializer runs doesn't particularly matter, it's generally
    /// safe to set its priority as `0`.
    fn priority(&self, state: &S) -> i32;

    fn after_router(
        &self,
        #[allow(unused_variables)] state: &S,
        router: Router,
    ) -> Result<Router, Self::Error> {
        Ok(router)
    }

    fn before_middleware(
        &self,
        #[allow(unused_variables)] state: &S,
        router: Router,
    ) -> Result<Router, Self::Error> {
        Ok(router)
    }

    fn after_middleware(
        &self,
        #[allow(unused_variables)] state: &S,
        router: Router,
    ) -> Result<Router, Self::Error> {
        Ok(router)
    }

    fn before_serve(
        &self,
        #[allow(unused_variables)] state: &S,
        router: Router,
    ) -> Result<Router, Self::Error> {
        Ok(router)
    }
}