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