rsiot/components/cmp_esp_nvs/
component.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
use async_trait::async_trait;
use serde::{de::DeserializeOwned, Serialize};

use crate::{
    executor::{CmpInOut, Component, ComponentError, IComponentProcess},
    message::{AuthPermissions, MsgDataBound, ServiceBound},
};

use super::config::Config;
#[cfg(feature = "single-thread")]
use super::fn_process::fn_process;

#[allow(unreachable_code)]
#[cfg(not(feature = "single-thread"))]
#[async_trait]
impl<TMsg, TStorageData> IComponentProcess<Config<TMsg, TStorageData>, TMsg>
    for Component<Config<TMsg, TStorageData>, TMsg>
where
    TMsg: MsgDataBound + 'static,
    TStorageData: std::fmt::Debug + Default + DeserializeOwned + PartialEq + Serialize,
{
    async fn process(
        &self,
        config: Config<TMsg, TStorageData>,
        input: CmpInOut<TMsg>,
    ) -> Result<(), ComponentError> {
        unimplemented!();
    }
}

#[cfg(feature = "single-thread")]
#[async_trait(?Send)]
impl<TMsg, TService, TStorageData> IComponentProcess<Config<TMsg, TStorageData>, TMsg, TService>
    for Component<Config<TMsg, TStorageData>, TMsg, TService>
where
    TMsg: MsgDataBound + 'static,
    TService: ServiceBound + 'static,
    TStorageData: std::fmt::Debug + Default + DeserializeOwned + PartialEq + Serialize + 'static,
{
    async fn process(
        &self,
        config: Config<TMsg, TStorageData>,
        in_out: CmpInOut<TMsg, TService>,
    ) -> Result<(), ComponentError> {
        let in_out = in_out.clone_with_new_id("cmp_storage_esp", AuthPermissions::FullAccess);
        fn_process(in_out, config)
            .await
            .map_err(|err| ComponentError::Execution(err.to_string()))
    }
}

/// Компонент cmp_storage_esp
pub type Cmp<TMsg, TService, TStorageData> = Component<Config<TMsg, TStorageData>, TMsg, TService>;