What is the Service trait in Motore?
mainThe core abstraction in Motore is the Service trait. It is an async middleware abstraction designed to reduce the mental burden of writing asynchronous code by leveraging AFIT (Async Functions in Traits) and RPITIT (Return Position Impl Trait in Traits). This approach avoids the need for manual Boxing of futures, making the code more concise and performant.
To implement a service, you define how it processes a request given a context (Cx) and returns a Result containing either a Response or an Error asynchronously.
pub trait Service<Cx, Request> {
/// Responses given by the service.
type Response;
/// Errors produced by the service.
type Error;
/// Process the request and return the response asynchronously.
async fn call(&self, cx: &mut Cx, req: Request) -> Result<Self::Response, Self::Error>;
}