cgp_dispatch/providers/with_handlers/
match_first_with_handlers_mut.rs1use core::marker::PhantomData;
2
3use cgp_core::prelude::*;
4use cgp_handler::{AsyncComputer, AsyncComputerComponent, Computer, ComputerComponent};
5
6use crate::DispatchMatchers;
7
8pub struct MatchFirstWithHandlersMut<Handlers>(pub PhantomData<Handlers>);
9
10#[cgp_provider]
11impl<'a, Context, Code, Input, Args, Output, Remainder, Handlers>
12 Computer<Context, Code, (&'a mut Input, Args)> for MatchFirstWithHandlersMut<Handlers>
13where
14 Input: HasExtractorMut,
15 DispatchMatchers<Handlers>: Computer<
16 Context,
17 Code,
18 (Input::ExtractorMut<'a>, Args),
19 Output = Result<Output, (Remainder, Args)>,
20 >,
21 Remainder: FinalizeExtract,
22{
23 type Output = Output;
24
25 fn compute(
26 context: &Context,
27 code: PhantomData<Code>,
28 (input, args): (&'a mut Input, Args),
29 ) -> Output {
30 let res = DispatchMatchers::compute(context, code, (input.extractor_mut(), args));
31 match res {
32 Ok(output) => output,
33 Err((remainder, _)) => remainder.finalize_extract(),
34 }
35 }
36}
37
38#[cgp_provider]
39impl<'a, Context, Code, Input, Args, Output, Remainder, Handlers>
40 AsyncComputer<Context, Code, (&'a mut Input, Args)> for MatchFirstWithHandlersMut<Handlers>
41where
42 Input: HasExtractorMut,
43 DispatchMatchers<Handlers>: AsyncComputer<
44 Context,
45 Code,
46 (Input::ExtractorMut<'a>, Args),
47 Output = Result<Output, (Remainder, Args)>,
48 >,
49 Remainder: FinalizeExtract,
50{
51 type Output = Output;
52
53 async fn compute_async(
54 context: &Context,
55 code: PhantomData<Code>,
56 (input, args): (&'a mut Input, Args),
57 ) -> Output {
58 let res =
59 DispatchMatchers::compute_async(context, code, (input.extractor_mut(), args)).await;
60
61 match res {
62 Ok(output) => output,
63 Err((remainder, _)) => remainder.finalize_extract(),
64 }
65 }
66}