rsiot/components/cmp_esp_uart_slave/tasks/
input.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
use crate::{
    executor::CmpInOut,
    message::{MsgDataBound, ServiceBound},
};

use super::{super::config::TFnInput, Buffer};

pub struct Input<TMsg, TService, TBufferData>
where
    TMsg: MsgDataBound,
    TService: ServiceBound,
{
    pub buffer_data: Buffer<TBufferData>,
    pub msg_bus: CmpInOut<TMsg, TService>,
    pub fn_input: TFnInput<TMsg, TBufferData>,
}

impl<TMsg, TService, TBufferData> Input<TMsg, TService, TBufferData>
where
    TMsg: MsgDataBound,
    TService: ServiceBound,
{
    pub async fn spawn(mut self) -> super::Result<()> {
        while let Ok(msg) = self.msg_bus.recv_input().await {
            let mut buffer_data = self.buffer_data.lock().await;
            (self.fn_input)(&msg, &mut buffer_data);
        }
        Ok(())
    }
}