Skip to main content

saddle_service/
contract.rs

1use std::{future::Future, pin::Pin};
2
3use saddle_core::{CallContext, Result};
4
5/// The boxed asynchronous boundary used by V1 Service implementations.
6pub type ServiceFuture<'a, T> = Pin<Box<dyn Future<Output = Result<T>> + Send + 'a>>;
7
8/// One strongly typed asynchronous Service operation contract.
9///
10/// This type contains no implementation behavior. Callers depend on a public
11/// contract type implementing this trait; a private implementation separately
12/// implements [`ServiceHandler<Self>`].
13pub trait Service: Send + Sync + 'static {
14    type Request: Send + 'static;
15    type Response: Send + 'static;
16}
17
18/// The implementation boundary for a Service contract `S`.
19pub trait ServiceHandler<S: Service>: Send + Sync + 'static {
20    fn call<'a>(
21        &'a self,
22        context: &'a CallContext,
23        request: S::Request,
24    ) -> ServiceFuture<'a, S::Response>;
25}