mod config;
mod counter;
mod environment;
mod events;
mod handlers;
pub mod services;
mod state;
use continuo::{Register, Result, Runtime};
pub use environment::Environment;
use state::AppState;
#[derive(Default)]
pub struct Application {
environment: Environment,
runtime: Runtime<AppState>,
}
impl Application {
pub fn new() -> Self {
Self::default()
}
pub fn with_environment(
mut self,
environment: Environment,
) -> Self {
self.environment = environment;
self
}
pub fn with_services<R: Register<AppState>>(mut self) -> Self {
self.runtime = self.runtime.with_services::<R>();
self
}
pub async fn run(self) -> Result<()> {
let state = AppState::new(self.environment.store()?)?;
let finalized = self.runtime.serve(state).await?;
for failure in finalized.failures() {
eprintln!(
"finalize failed for {}: {}",
failure.component(),
failure.error()
);
}
Ok(())
}
}