ntex-server 4.1.1

Server for ntex framework
Documentation
#![allow(clippy::unused_async_trait_impl)]
use std::io;

/// Creates application state independently for each server worker.
pub trait ServerAppConfig: Sync + Send + 'static {
    /// State stored by each worker.
    type State: Clone;

    /// Creates state for one worker.
    async fn create(&self) -> io::Result<Self::State>;
}

/// Application configuration that creates unit state.
#[derive(Copy, Clone, Default, Debug)]
pub struct NoConfig;

impl ServerAppConfig for NoConfig {
    type State = ();

    async fn create(&self) -> io::Result<()> {
        Ok(())
    }
}

impl<F, Cfg> ServerAppConfig for F
where
    F: AsyncFn() -> io::Result<Cfg> + Sync + Send + 'static,
    Cfg: Clone,
{
    type State = Cfg;

    async fn create(&self) -> io::Result<Cfg> {
        (*self)().await
    }
}