Nouzan / exc

An abstraction layer for exchanges
MIT License
38 stars 14 forks source link

Refine the "adaptor" API with a new `AdaptService` trait #69

Closed Nouzan closed 12 months ago

Nouzan commented 12 months ago

We use the following AdaptService trait to extend the original Adaptor trait:

/// Service that can handle request [`R`] with its inner request [`Req`].
pub trait AdaptService<Req, R>: ExcService<Req>
where
    Req: Request,
    R: Request,
{
    /// Future returned by [`AdaptService::into_response`].
    type AdaptedResponse: Future<Output = Result<R::Response, ExchangeError>>;

    /// Adapt the request.
    fn from_request(&mut self, req: R) -> Result<Req, ExchangeError>;

    /// Adapt the response future
    fn into_response(&mut self, res: Self::Future) -> Self::AdaptedResponse;
}

With AdaptService, we can now be able to insert extra information from a concrete exchange service into the request.