saddle-service 0.1.1

Saddle Service contracts, registration and invocation
Documentation
use std::{future::Future, pin::Pin};

use saddle_core::{CallContext, Result};

/// The boxed asynchronous boundary used by V1 Service implementations.
pub type ServiceFuture<'a, T> = Pin<Box<dyn Future<Output = Result<T>> + Send + 'a>>;

/// One strongly typed asynchronous Service operation contract.
///
/// This type contains no implementation behavior. Callers depend on a public
/// contract type implementing this trait; a private implementation separately
/// implements [`ServiceHandler<Self>`].
pub trait Service: Send + Sync + 'static {
    type Request: Send + 'static;
    type Response: Send + 'static;
}

/// The implementation boundary for a Service contract `S`.
pub trait ServiceHandler<S: Service>: Send + Sync + 'static {
    fn call<'a>(
        &'a self,
        context: &'a CallContext,
        request: S::Request,
    ) -> ServiceFuture<'a, S::Response>;
}