Skip to main content

cgp_handler/providers/
promote_async.rs

1use cgp_core::prelude::*;
2
3use crate::{
4    AsyncComputer, AsyncComputerComponent, Computer, Handler, HandlerComponent, TryComputer,
5};
6
7pub struct PromoteAsync<Provider>(pub PhantomData<Provider>);
8
9#[cgp_provider]
10impl<Context, Code, Input, Output, Provider> AsyncComputer<Context, Code, Input>
11    for PromoteAsync<Provider>
12where
13    Provider: Computer<Context, Code, Input, Output = Output>,
14{
15    type Output = Output;
16
17    async fn compute_async(context: &Context, tag: PhantomData<Code>, input: Input) -> Output {
18        Provider::compute(context, tag, input)
19    }
20}
21
22#[cgp_provider]
23impl<Context, Code, Input, Output, Provider> Handler<Context, Code, Input>
24    for PromoteAsync<Provider>
25where
26    Context: HasErrorType,
27    Provider: TryComputer<Context, Code, Input, Output = Output>,
28{
29    type Output = Output;
30
31    async fn handle(
32        context: &Context,
33        tag: PhantomData<Code>,
34        input: Input,
35    ) -> Result<Output, Context::Error> {
36        Provider::try_compute(context, tag, input)
37    }
38}