use std::time::Duration;
#[allow(async_fn_in_trait)]
pub trait Transport: Send + Sync {
async fn send(
&self,
address: &str,
port: u16,
data: &[u8],
timeout: Duration,
) -> Result<Vec<u8>, TransportError>;
fn is_connected(&self) -> bool;
async fn close(&self);
}
#[derive(Debug, thiserror::Error)]
pub enum TransportError {
#[error("Connection failed: {0}")]
ConnectionFailed(String),
#[error("Send failed: {0}")]
SendFailed(String),
#[error("Receive failed: {0}")]
ReceiveFailed(String),
#[error("Timeout")]
Timeout,
#[error("Connection closed")]
ConnectionClosed,
#[error("TLS error: {0}")]
TlsError(String),
#[error("{0}")]
Other(String),
}