rsiot/components/cmp_derive_new/
component.rs1use async_trait::async_trait;
2
3use crate::{
4 executor::{Component, ComponentError, IComponentProcess, MsgBusLinker},
5 message::*,
6};
7
8use super::{BufferBound, Config, fn_process::fn_process};
9
10pub const COMPONENT_NAME: &str = "cmp_derive";
12
13#[cfg_attr(not(feature = "single-thread"), async_trait)]
14#[cfg_attr(feature = "single-thread", async_trait(?Send))]
15impl<TMsg, TBuffer> IComponentProcess<Config<TMsg, TBuffer>, TMsg>
16 for Component<Config<TMsg, TBuffer>, TMsg>
17where
18 TMsg: MsgDataBound + 'static,
19 TBuffer: 'static + BufferBound,
20{
21 async fn process(
22 &self,
23 config: Config<TMsg, TBuffer>,
24 msgbus_linker: MsgBusLinker<TMsg>,
25 ) -> Result<(), ComponentError> {
26 fn_process(msgbus_linker.init(COMPONENT_NAME), config)
27 .await
28 .map_err(|e| ComponentError::Execution(e.to_string()))
29 }
30}
31
32pub type Cmp<TMsg, TBuffer> = Component<Config<TMsg, TBuffer>, TMsg>;