mailfred 0.1.1

Process emails as an HTTP server
Documentation
pub mod response;
use std::future::Future;

use async_trait::async_trait;
pub use response::*;

use crate::message::Message;

pub type Request = Message;

/// Represents a service that processes a request and returns a response.
#[async_trait]
pub trait Service<State>: Send + Sync + 'static {
    async fn call(&self, req: Request, state: State) -> ResponseResult;
}

#[async_trait]
impl<State, F, Fut> Service<State> for F
where
    F: Fn(Request, State) -> Fut + Send + Sync + 'static,
    Fut: Future<Output = ResponseResult> + Send,
    State: Send + 'static,
{
    async fn call(&self, req: Request, state: State) -> ResponseResult {
        (self)(req, state).await
    }
}