use std::{ops, path};
use super::ApplicationState;
use crate::logger_settings_site::applications::web;
pub type ApplicationCLI = ();
pub type ApplicationEnv = ();
pub struct Application {
application: lexa_framework::DefaultApplication<
ApplicationEnv,
ApplicationCLI,
ApplicationState,
>,
}
#[derive(Debug)]
#[derive(thiserror::Error)]
#[error(
"\n\t[{}]: erreur applicative. Raison: {0}",
std::any::type_name::<Self>()
)]
pub enum ApplicationError {
LexaFramework(#[from] lexa_framework::ApplicationError),
}
impl Application {
pub async fn new(
application_name: impl ToString,
application_version: impl ToString,
application_root_dir: impl AsRef<path::Path>,
) -> Result<Self, ApplicationError> {
let framework_application = lexa_framework::DefaultApplication::create(
application_name.to_string().leak(),
application_version.to_string().leak(),
application_root_dir.as_ref(),
lexa_framework::ApplicationSettingsLoaderExtension::YAML,
)
.await?;
Ok(Self {
application: framework_application,
})
}
pub fn setup(mut self) -> Self {
self.application.server = self
.application
.server
.make_application::<web::PagesApplication>();
self
}
pub async fn run(self) -> Result<(), ApplicationError> {
log::info!("Hello World");
Ok(self.application.run().await?)
}
}
impl ops::Deref for Application {
type Target = lexa_framework::DefaultApplication<
ApplicationEnv,
ApplicationCLI,
ApplicationState,
>;
fn deref(&self) -> &Self::Target {
&self.application
}
}
impl ops::DerefMut for Application {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.application
}
}