use super::config::StreamConfig;
use async_trait::async_trait;
use std::net::SocketAddr;
#[async_trait]
pub trait StreamProtocol {
type Error: Send + Into<crate::EchoError>;
type Listener: Send;
type Stream: Send;
async fn bind(config: &StreamConfig) -> std::result::Result<Self::Listener, Self::Error>;
async fn accept(
listener: &mut Self::Listener,
) -> std::result::Result<(Self::Stream, SocketAddr), Self::Error>;
async fn connect(addr: SocketAddr) -> std::result::Result<Self::Stream, Self::Error>;
async fn read(
stream: &mut Self::Stream,
buffer: &mut [u8],
) -> std::result::Result<usize, Self::Error>;
async fn write(stream: &mut Self::Stream, data: &[u8]) -> std::result::Result<(), Self::Error>;
async fn flush(stream: &mut Self::Stream) -> std::result::Result<(), Self::Error>;
fn map_io_error(err: std::io::Error) -> Self::Error;
}