capy-core 0.10.0

Typed configuration, application context, and errors for the Capy web framework.
Documentation
//! Typed configuration, shared application state, and safe application errors.

mod auth_config;
mod password_config;
pub use password_config::{HashConcurrency, PasswordSettings};
mod client_ip;
mod config;
pub use client_ip::{ClientIpResolver, ClientIpSettings, ClientIpStrategy};
mod jobs_config;
mod mail_config;
pub use auth_config::{AuthSettings, AuthThrottleLimit, AuthThrottleSettings, SameSite};
pub use jobs_config::JobsSettings;
pub use mail_config::{MailSecret, MailSettings, SmtpSettings};
mod error;
mod event_error;
mod events;
mod services;
mod storage_config;
pub use event_error::{EventError, EventRejection, EventResult};
pub use events::{Event, EventBus, EventContext, EventFuture, Events};
pub use services::{Service, Services};
pub use storage_config::StorageSettings;

pub use config::{
    ApiSettings, AppConfig, AppSettings, DatabaseSettings, HttpSettings, ServerSettings,
};
pub use error::{ApiErrorResponse, AppError, ErrorKind, Result, ValidationErrors};
use std::sync::Arc;

/// Cheaply cloned state shared by every request.
#[derive(Clone, Debug)]
pub struct AppContext {
    /// Validated, immutable application configuration.
    pub config: Arc<AppConfig>,
    /// SeaORM's native connection pool.
    pub db: sea_orm::DatabaseConnection,
}

/// Extract typed application state using `Context(ctx): Context`.
#[derive(Clone, Debug)]
pub struct Context(pub AppContext);

impl axum::extract::FromRequestParts<AppContext> for Context {
    type Rejection = std::convert::Infallible;

    async fn from_request_parts(
        _parts: &mut axum::http::request::Parts,
        state: &AppContext,
    ) -> std::result::Result<Self, Self::Rejection> {
        Ok(Self(state.clone()))
    }
}