cgp_dispatch/providers/with_handlers/
match_with_handlers_ref.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 MatchWithHandlersRef<Handlers>(pub PhantomData<Handlers>);
10
11#[cgp_provider]
12impl<'a, Context, Code, Input, Output, Remainder, Handlers> Computer<Context, Code, &'a Input>
13 for MatchWithHandlersRef<Handlers>
14where
15 Input: HasExtractorRef,
16 DispatchMatchers<Handlers>:
17 Computer<Context, Code, Input::ExtractorRef<'a>, Output = Result<Output, Remainder>>,
18 Remainder: FinalizeExtract,
19{
20 type Output = Output;
21
22 fn compute(context: &Context, code: PhantomData<Code>, input: &'a Input) -> Output {
23 DispatchMatchers::compute(context, code, input.extractor_ref()).finalize_extract_result()
24 }
25}
26
27#[cgp_provider]
28impl<'a, Context, Code, Input, Output, Remainder, Handlers> AsyncComputer<Context, Code, &'a Input>
29 for MatchWithHandlersRef<Handlers>
30where
31 Input: HasExtractorRef,
32 DispatchMatchers<Handlers>:
33 AsyncComputer<Context, Code, Input::ExtractorRef<'a>, Output = Result<Output, Remainder>>,
34 Remainder: FinalizeExtract,
35{
36 type Output = Output;
37
38 async fn compute_async(context: &Context, code: PhantomData<Code>, input: &'a Input) -> Output {
39 DispatchMatchers::compute_async(context, code, input.extractor_ref())
40 .await
41 .finalize_extract_result()
42 }
43}