Skip to main content

rsiot/components/cmp_file_appender/
component.rs

1use async_trait::async_trait;
2
3use crate::{
4    executor::{CmpResult, Component, IComponentProcess, MsgBusLinker},
5    message::MsgDataBound,
6};
7
8use super::{ConfigAction, config::Config, fn_process::fn_process};
9
10/// Название компонента
11pub const COMPONENT_NAME: &str = "cmp_file_appender";
12
13#[cfg_attr(not(feature = "single-thread"), async_trait)]
14#[cfg_attr(feature = "single-thread", async_trait(?Send))]
15impl<TMsg, TFnInput> IComponentProcess<Config<TMsg, TFnInput>, TMsg>
16    for Component<Config<TMsg, TFnInput>, TMsg>
17where
18    TMsg: MsgDataBound + 'static,
19    TFnInput: 'static + Fn(TMsg) -> ConfigAction + Send + Sync,
20{
21    async fn process(
22        &self,
23        config: Config<TMsg, TFnInput>,
24        msgbus_linker: MsgBusLinker<TMsg>,
25    ) -> CmpResult {
26        fn_process(config, msgbus_linker.init(COMPONENT_NAME)).await?;
27        Ok(())
28    }
29}
30
31/// Компонент cmp_file_appender
32pub type Cmp<TMsg, TFnInput> = Component<Config<TMsg, TFnInput>, TMsg>;