use std::net::SocketAddr; use crate::Error; // This is the data transmission type pub trait Connection: Send + Sync { fn get_info(&self) -> String; fn is_alive(&self) -> bool; fn read(&mut self) -> Result; fn write(&mut self, data: &str) -> Result<(), Error>; fn try_clone(&self) -> Result, Error>; } // Trait for protocol layers that can be initialized pub trait ProtocolLayer: Connection { fn new(inner: Box) -> Result where Self: Sized; fn initialize_client(&mut self) -> Result<(), Error> { Ok(()) } fn initialize_server(&mut self) -> Result<(), Error> { Ok(()) } } // impl Sized for dyn Connection {} // pub trait AsyncConnection // where // C: Connection, // { // fn as_async( // connection: C, // ) -> (Sender, Receiver); // } pub trait ServerTrait { fn get_info(&self) -> String; fn accept(&self) -> Result; fn bind(address: &SocketAddr) -> Result where Self: Sized; } pub trait ClientTrait { fn connect(address: &SocketAddr) -> Result; }