Skip to main content

rsiot/components_config/http_server/
config.rs

1use crate::message::MsgDataBound;
2
3use super::{GetEndpoint, PutEndpoint};
4
5// ANCHOR: Config
6/// Конфигурация компонента http-server
7#[derive(Clone, Debug)]
8pub struct Config<TMsg>
9where
10    TMsg: MsgDataBound,
11{
12    /// Порт, через который доступен сервер
13    pub port: u16,
14
15    /// Функция, разрешающая запуск сервера
16    ///
17    /// Может быть полезна в cmp_esp_http_server, в ожидании подключения к сети
18    ///
19    /// Если функция не нужна, то можно передать `|_| Some(true)`
20    pub fn_start: fn(&TMsg) -> Option<bool>,
21
22    /// Конфигурация точек GET
23    pub get_endpoints: Vec<Box<dyn GetEndpoint<TMsg>>>,
24
25    /// Конфигурация точек PUT
26    pub put_endpoints: Vec<Box<dyn PutEndpoint<TMsg>>>,
27}
28// ANCHOR: Config
29
30#[cfg(test)]
31mod tests {
32    use super::Config;
33    use crate::message::example_message::*;
34
35    #[allow(clippy::no_effect)]
36    #[test]
37    fn stub() {
38        Config::<Custom> {
39            port: 8000,
40            fn_start: |_| Some(true),
41            get_endpoints: vec![],
42            put_endpoints: vec![],
43        };
44    }
45
46    #[allow(clippy::no_effect)]
47    #[test]
48    fn fn_input_json() {
49        Config::<Custom> {
50            port: 8000,
51            fn_start: |_| Some(true),
52            get_endpoints: vec![],
53            put_endpoints: vec![],
54        };
55    }
56
57    #[allow(clippy::no_effect)]
58    #[test]
59    fn fn_output_json() {
60        Config::<Custom> {
61            port: 8000,
62            fn_start: |_| Some(true),
63            get_endpoints: vec![],
64            put_endpoints: vec![],
65        };
66    }
67}