Skip to main content

plato_mud/transport/
mod.rs

1//! PLATO MUD Engine — Transport Adapters
2//!
3//! Each adapter implements the Transport trait for FLUX transference
4//! over different physical/virtual transports.
5
6pub mod memory;
7
8use crate::types::{FluxTransference, TransportConfig};
9
10/// Result type for transport operations
11pub type Result<T> = core::result::Result<T, TransportError>;
12
13/// Transport error types
14#[derive(Debug)]
15pub enum TransportError {
16    ConnectionFailed(String),
17    SendFailed(String),
18    ReceiveFailed(String),
19    NotConnected,
20    InvalidConfig(String),
21}
22
23/// The transport trait — all adapters implement this
24pub trait Transport {
25    fn connect(&mut self, config: &TransportConfig) -> Result<()>;
26    fn send_flux(&mut self, flux: &FluxTransference) -> Result<()>;
27    fn recv_flux(&mut self) -> Result<FluxTransference>;
28    fn disconnect(&mut self) -> Result<()>;
29    fn is_connected(&self) -> bool;
30}
31
32#[cfg(test)]
33mod tests {
34    use super::*;
35    use crate::transport::memory::MemoryTransport;
36
37    #[test]
38    fn test_memory_transport_lifecycle() {
39        let config = TransportConfig {
40            transport_type: "memory".to_string(),
41            address: "local".to_string(),
42            port: 0,
43            options: Default::default(),
44        };
45
46        let mut transport = MemoryTransport::new();
47        assert!(!transport.is_connected());
48
49        transport.connect(&config).unwrap();
50        assert!(transport.is_connected());
51
52        transport.disconnect().unwrap();
53        assert!(!transport.is_connected());
54    }
55}