Skip to main content

GotchaApp

Trait GotchaApp 

Source
pub trait GotchaApp:
    Sized
    + Send
    + Sync {
    type State: Clone + Send + Sync + 'static;
    type Config: Clone + Send + Sync + 'static + Serialize + for<'de> Deserialize<'de> + Default;

    // Required methods
    fn routes(
        &self,
        router: GotchaRouter<GotchaContext<Self::State, Self::Config>>,
    ) -> GotchaRouter<GotchaContext<Self::State, Self::Config>>;
    fn state(
        &self,
        config: &ConfigWrapper<Self::Config>,
    ) -> impl Future<Output = GotchaResult<Self::State>> + Send;

    // Provided methods
    fn config(
        &self,
    ) -> impl Future<Output = GotchaResult<ConfigWrapper<Self::Config>>> + Send { ... }
    fn logger(&self) -> GotchaResult<()> { ... }
    fn tasks(
        &self,
        _task_scheduler: &mut TaskScheduler<Self::State, Self::Config>,
    ) -> impl Future<Output = GotchaResult<()>> + Send { ... }
    fn build_router(
        &self,
        context: GotchaContext<Self::State, Self::Config>,
    ) -> impl Future<Output = GotchaResult<Router>> + Send { ... }
    fn run(self) -> impl Future<Output = GotchaResult<()>> + Send { ... }
}
Expand description

The trait API: implement it to describe an application, then call run().

The builder (Gotcha) is the simpler alternative; both assemble the router through the same path, so they behave identically.

Required Associated Types§

Source

type State: Clone + Send + Sync + 'static

The application state, shared by every handler.

Source

type Config: Clone + Send + Sync + 'static + Serialize + for<'de> Deserialize<'de> + Default

The application’s own configuration, read from the top level of the config file.

Required Methods§

Source

fn routes( &self, router: GotchaRouter<GotchaContext<Self::State, Self::Config>>, ) -> GotchaRouter<GotchaContext<Self::State, Self::Config>>

Register the application’s routes.

Source

fn state( &self, config: &ConfigWrapper<Self::Config>, ) -> impl Future<Output = GotchaResult<Self::State>> + Send

Build the application state, given the loaded configuration.

Provided Methods§

Source

fn config( &self, ) -> impl Future<Output = GotchaResult<ConfigWrapper<Self::Config>>> + Send

Load the configuration. The default honours GOTCHA_ACTIVE_PROFILE.

Source

fn logger(&self) -> GotchaResult<()>

Install the tracing subscriber. The default reads RUST_LOG.

Source

fn tasks( &self, _task_scheduler: &mut TaskScheduler<Self::State, Self::Config>, ) -> impl Future<Output = GotchaResult<()>> + Send

Available on crate feature task only.

Register background tasks. The default registers none.

Source

fn build_router( &self, context: GotchaContext<Self::State, Self::Config>, ) -> impl Future<Output = GotchaResult<Router>> + Send

Assemble the final axum router. Override only to wrap the whole application.

Source

fn run(self) -> impl Future<Output = GotchaResult<()>> + Send

Load configuration, build state and routes, then serve until shutdown.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§