use crate::encoding::Message; use anyhow::Result; use tcp::TcpTransport; use udp::UdpTransport; pub mod tcp; pub mod udp; #[allow(async_fn_in_trait)] pub trait Transport { async fn recv(&self) -> Result; async fn send(&self, message: Message) -> Result<()>; } pub enum InetTransport { Udp(UdpTransport), Tcp(TcpTransport), } impl Transport for InetTransport { async fn recv(&self) -> Result { match self { InetTransport::Udp(t) => t.recv().await, InetTransport::Tcp(t) => t.recv().await, } } async fn send(&self, message: Message) -> Result<()> { match self { InetTransport::Udp(t) => t.send(message).await, InetTransport::Tcp(t) => t.send(message).await, } } }