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