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§
Required Methods§
Sourcefn routes(
&self,
router: GotchaRouter<GotchaContext<Self::State, Self::Config>>,
) -> GotchaRouter<GotchaContext<Self::State, Self::Config>>
fn routes( &self, router: GotchaRouter<GotchaContext<Self::State, Self::Config>>, ) -> GotchaRouter<GotchaContext<Self::State, Self::Config>>
Register the application’s routes.
Sourcefn state(
&self,
config: &ConfigWrapper<Self::Config>,
) -> impl Future<Output = GotchaResult<Self::State>> + Send
fn state( &self, config: &ConfigWrapper<Self::Config>, ) -> impl Future<Output = GotchaResult<Self::State>> + Send
Build the application state, given the loaded configuration.
Provided Methods§
Sourcefn config(
&self,
) -> impl Future<Output = GotchaResult<ConfigWrapper<Self::Config>>> + Send
fn config( &self, ) -> impl Future<Output = GotchaResult<ConfigWrapper<Self::Config>>> + Send
Load the configuration. The default honours GOTCHA_ACTIVE_PROFILE.
Sourcefn logger(&self) -> GotchaResult<()>
fn logger(&self) -> GotchaResult<()>
Install the tracing subscriber. The default reads RUST_LOG.
Sourcefn tasks(
&self,
_task_scheduler: &mut TaskScheduler<Self::State, Self::Config>,
) -> impl Future<Output = GotchaResult<()>> + Send
Available on crate feature task only.
fn tasks( &self, _task_scheduler: &mut TaskScheduler<Self::State, Self::Config>, ) -> impl Future<Output = GotchaResult<()>> + Send
task only.Register background tasks. The default registers none.
Sourcefn build_router(
&self,
context: GotchaContext<Self::State, Self::Config>,
) -> impl Future<Output = GotchaResult<Router>> + Send
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.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".