cgp_handler/components/
handler.rs

1use core::marker::PhantomData;
2
3use cgp_core::component::UseDelegate;
4use cgp_core::prelude::*;
5
6use crate::UseInputDelegate;
7
8#[async_trait]
9#[cgp_component {
10    provider: Handler,
11    derive_delegate: [
12        UseDelegate<Code>,
13        UseInputDelegate<Input>,
14    ],
15}]
16pub trait CanHandle<Code, Input>: HasAsyncErrorType {
17    type Output;
18
19    async fn handle(
20        &self,
21        _tag: PhantomData<Code>,
22        input: Input,
23    ) -> Result<Self::Output, Self::Error>;
24}
25
26#[async_trait]
27#[cgp_component {
28    provider: HandlerRef,
29    derive_delegate: [
30        UseDelegate<Code>,
31        UseInputDelegate<Input>,
32    ],
33}]
34pub trait CanHandleRef<Code, Input>: HasAsyncErrorType {
35    type Output;
36
37    async fn handle_ref(
38        &self,
39        _tag: PhantomData<Code>,
40        input: &Input,
41    ) -> Result<Self::Output, Self::Error>;
42}