tramex_tools/interface/
interface_types.rs

1//! Interface module
2
3use crate::data::Data;
4use crate::errors::TramexError;
5use crate::interface::interface_file::file_handler::File;
6use crate::interface::layer::Layers;
7#[cfg(feature = "websocket")]
8use crate::interface::websocket::ws_connection::WsConnection;
9
10/// Interface enum
11pub enum Interface {
12    /// WebSocket connection
13    #[cfg(feature = "websocket")]
14    Ws(WsConnection),
15
16    /// File
17    File(File),
18}
19
20/// Interface trait
21pub trait InterfaceTrait {
22    /// Get more data
23    /// # Errors
24    /// Return an error if the data is not received correctly
25    fn get_more_data(&mut self, _layer_list: Layers, data: &mut Data) -> Result<(), Vec<TramexError>>;
26
27    /// Try to close the interface
28    /// # Errors
29    /// Return an error if its fail
30    fn close(&mut self) -> Result<(), TramexError>;
31
32    /// Check if this interface supports preloading (e.g., file can preload, websocket cannot)
33    fn supports_preloading(&self) -> bool {
34        false
35    }
36
37    /// Get total event count if known (Some for files, None for websockets)
38    fn get_total_event_count(&self) -> Option<usize> {
39        None
40    }
41
42    /// Check if all data has been read
43    fn is_fully_read(&self) -> bool;
44}
45
46impl core::fmt::Debug for Interface {
47    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
48        f.debug_struct("Interface")
49            .field(
50                "field",
51                match self {
52                    #[cfg(feature = "websocket")]
53                    Interface::Ws(ws) => ws,
54                    Interface::File(file) => file,
55                },
56            )
57            .finish()
58    }
59}