use thiserror::Error;
use tokio::io::{AsyncRead, AsyncWrite};
use tokio::net::TcpStream;
pub trait DuplexStream: AsyncRead + AsyncWrite + Unpin + Send {}
impl<T: AsyncRead + AsyncWrite + Unpin + Send + ?Sized> DuplexStream for T {}
#[derive(Debug, Error)]
pub enum RaftHandshakeError {
#[error("io: {0}")]
Io(#[from] std::io::Error),
#[error("tls: {0}")]
Tls(String),
#[error("sasl: {0}")]
Sasl(String),
#[error("protocol: {0}")]
Protocol(String),
}
#[async_trait::async_trait]
pub trait RaftListenerHandshake: Send + Sync {
async fn upgrade(&self, stream: TcpStream)
-> Result<Box<dyn DuplexStream>, RaftHandshakeError>;
}