diff --git a/src/main.rs b/src/main.rs index e5e775f..06f1766 100644 --- a/src/main.rs +++ b/src/main.rs @@ -23,6 +23,7 @@ use crate::states::AppState; async fn init() -> Result<()> { let app_state = AppState::build()?; + // The path prefix of all routes. let path_prefix = app_state.config.path_prefix.clone(); let socket_address = app_state @@ -37,6 +38,7 @@ async fn init() -> Result<()> { app_state.config.utc_offset.minutes, )?; + // The service for serving the static files. let static_service = get_service(ServeDir::new("static")).handle_error(|_| ready(StatusCode::NOT_FOUND)); diff --git a/src/states.rs b/src/states.rs index 2238fdb..330f935 100644 --- a/src/states.rs +++ b/src/states.rs @@ -4,6 +4,7 @@ use std::sync::{Arc, Mutex}; use crate::{captcha_solutions::CaptchaSolutions, config::Config, mailer::Mailer}; +/// The application state. #[derive(Clone, FromRef)] pub struct AppState { pub config: Arc, @@ -12,11 +13,13 @@ pub struct AppState { } impl AppState { + /// Try to build the app state. pub fn build() -> Result { let config = Config::build()?; let mailer = Arc::new(Mailer::build(&config)?); let config = Arc::new(config); + // Mutex for write access. let captcha_solutions = Arc::new(Mutex::new(CaptchaSolutions::default())); Ok(Self { diff --git a/src/templates.rs b/src/templates.rs index b56dbf8..47bd51d 100644 --- a/src/templates.rs +++ b/src/templates.rs @@ -2,11 +2,13 @@ use askama::Template; use crate::{config, forms::PersistantContactFormFields}; +/// Base template. pub struct Base<'a> { pub lang: &'a str, pub path_prefix: &'a str, } +/// Contact form template. #[derive(Template)] #[template(path = "contact_form.askama.html")] pub struct ContactForm<'a> { @@ -19,6 +21,7 @@ pub struct ContactForm<'a> { pub strings: &'a config::Strings, } +/// Sucessful contact form submission template. #[derive(Template)] #[template(path = "success.askama.html")] pub struct Success<'a> {