rsiot/components/cmp_esp_nvs/
component.rs1use async_trait::async_trait;
2use serde::{Serialize, de::DeserializeOwned};
3
4use crate::{
5 executor::{Component, ComponentError, IComponentProcess, MsgBusLinker},
6 message::MsgDataBound,
7};
8
9use super::config::Config;
10#[cfg(feature = "single-thread")]
11use super::fn_process::fn_process;
12
13pub const COMPONENT_NAME: &str = "cmp_storage_esp";
14
15#[allow(unreachable_code)]
16#[cfg(not(feature = "single-thread"))]
17#[async_trait]
18impl<TMsg, TStorageData> IComponentProcess<Config<TMsg, TStorageData>, TMsg>
19 for Component<Config<TMsg, TStorageData>, TMsg>
20where
21 TMsg: MsgDataBound + 'static,
22 TStorageData: std::fmt::Debug + Default + DeserializeOwned + PartialEq + Serialize,
23{
24 async fn process(
25 &self,
26 config: Config<TMsg, TStorageData>,
27 input: MsgBusLinker<TMsg>,
28 ) -> Result<(), ComponentError> {
29 unimplemented!();
30 }
31}
32
33#[cfg(feature = "single-thread")]
34#[async_trait(?Send)]
35impl<TMsg, TStorageData> IComponentProcess<Config<TMsg, TStorageData>, TMsg>
36 for Component<Config<TMsg, TStorageData>, TMsg>
37where
38 TMsg: MsgDataBound + 'static,
39 TStorageData: std::fmt::Debug + Default + DeserializeOwned + PartialEq + Serialize + 'static,
40{
41 async fn process(
42 &self,
43 config: Config<TMsg, TStorageData>,
44 msgbus_linker: MsgBusLinker<TMsg>,
45 ) -> Result<(), ComponentError> {
46 fn_process(msgbus_linker.init(COMPONENT_NAME), config)
47 .await
48 .map_err(|err| ComponentError::Execution(err.to_string()))
49 }
50}
51
52pub type Cmp<TMsg, TStorageData> = Component<Config<TMsg, TStorageData>, TMsg>;