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