use crate::Protocol;
use crate::{duplex::Duplex, protocol::Options};
use futures_lite::io::{AsyncRead, AsyncWrite};
#[derive(Debug)]
pub struct Builder(Options);
impl Builder {
pub fn new(initiator: bool) -> Self {
Self(Options::new(initiator))
}
pub fn encrypted(mut self, encrypted: bool) -> Self {
self.0.encrypted = encrypted;
self
}
pub fn handshake(mut self, handshake: bool) -> Self {
self.0.noise = handshake;
self
}
pub fn connect<IO>(self, io: IO) -> Protocol<IO>
where
IO: AsyncRead + AsyncWrite + Send + Unpin + 'static,
{
Protocol::new(io, self.0)
}
pub fn connect_rw<R, W>(self, reader: R, writer: W) -> Protocol<Duplex<R, W>>
where
R: AsyncRead + Send + Unpin + 'static,
W: AsyncWrite + Send + Unpin + 'static,
{
let io = Duplex::new(reader, writer);
Protocol::new(io, self.0)
}
}