cgp_dispatch/providers/with_handlers/
match_with_handlers.rs1use core::marker::PhantomData;
2
3use cgp_core::field::traits::FinalizeExtractResult;
4use cgp_core::prelude::*;
5use cgp_handler::{AsyncComputer, AsyncComputerComponent, Computer, ComputerComponent};
6
7use crate::DispatchMatchers;
8
9pub struct MatchWithHandlers<Handlers>(pub PhantomData<Handlers>);
10
11#[cgp_provider]
12impl<Context, Code, Input, Output, Remainder, Handlers> Computer<Context, Code, Input>
13 for MatchWithHandlers<Handlers>
14where
15 Input: HasExtractor,
16 DispatchMatchers<Handlers>:
17 Computer<Context, Code, Input::Extractor, Output = Result<Output, Remainder>>,
18 Remainder: FinalizeExtract,
19{
20 type Output = Output;
21
22 fn compute(context: &Context, code: PhantomData<Code>, input: Input) -> Output {
23 DispatchMatchers::compute(context, code, input.to_extractor()).finalize_extract_result()
24 }
25}
26
27#[cgp_provider]
28impl<Context, Code, Input, Output, Remainder, Handlers> AsyncComputer<Context, Code, Input>
29 for MatchWithHandlers<Handlers>
30where
31 Input: HasExtractor,
32 DispatchMatchers<Handlers>:
33 AsyncComputer<Context, Code, Input::Extractor, Output = Result<Output, Remainder>>,
34 Remainder: FinalizeExtract,
35{
36 type Output = Output;
37
38 async fn compute_async(context: &Context, code: PhantomData<Code>, input: Input) -> Output {
39 DispatchMatchers::compute_async(context, code, input.to_extractor())
40 .await
41 .finalize_extract_result()
42 }
43}