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
//! Interface module

use crate::data::Data;
use crate::errors::TramexError;
use crate::interface::interface_file::file_handler::File;
use crate::interface::layer::Layers;
#[cfg(feature = "websocket")]
use crate::interface::websocket::ws_connection::WsConnection;

/// Interface enum
pub enum Interface {
    /// WebSocket connection
    #[cfg(feature = "websocket")]
    Ws(WsConnection),

    /// File
    File(File),
}

/// Interface trait
pub trait InterfaceTrait {
    /// Get more data
    /// # Errors
    /// Return an error if the data is not received correctly
    fn get_more_data(&mut self, _layer_list: Layers, data: &mut Data) -> Result<(), Vec<TramexError>>;

    /// Try to close the interface
    /// # Errors
    /// Return an error if its fail
    fn close(&mut self) -> Result<(), TramexError>;
}

impl core::fmt::Debug for Interface {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        f.debug_struct("Interface")
            .field(
                "field",
                match self {
                    #[cfg(feature = "websocket")]
                    Interface::Ws(ws) => ws,
                    Interface::File(file) => file,
                },
            )
            .finish()
    }
}