use crate::{
rng::{Xorshift64, simple_seed},
web_socket::WebSocketBuffer,
};
use core::array::IntoIter;
use httparse::Response;
#[derive(Debug)]
pub struct WebSocketConnector<C, H, R, RNG, WB> {
pub(crate) compression: C,
pub(crate) headers: H,
pub(crate) no_masking: bool,
pub(crate) res: R,
pub(crate) rng: RNG,
pub(crate) wsb: WB,
}
impl<C, H, R, RNG, WB> WebSocketConnector<C, H, R, RNG, WB> {
#[inline]
pub fn buffer<NWSB>(self, elem: NWSB) -> WebSocketConnector<C, H, R, RNG, NWSB> {
WebSocketConnector {
compression: self.compression,
headers: self.headers,
no_masking: self.no_masking,
res: self.res,
rng: self.rng,
wsb: elem,
}
}
#[inline]
pub fn compression<NC>(self, elem: NC) -> WebSocketConnector<NC, H, R, RNG, WB> {
WebSocketConnector {
compression: elem,
headers: self.headers,
no_masking: self.no_masking,
res: self.res,
rng: self.rng,
wsb: self.wsb,
}
}
#[inline]
pub fn headers<NH>(self, elem: NH) -> WebSocketConnector<C, NH, R, RNG, WB> {
WebSocketConnector {
compression: self.compression,
headers: elem,
no_masking: self.no_masking,
res: self.res,
rng: self.rng,
wsb: self.wsb,
}
}
#[inline]
pub const fn no_masking(mut self, elem: bool) -> WebSocketConnector<C, H, R, RNG, WB> {
self.no_masking = elem;
self
}
#[inline]
pub fn res<NR>(self, elem: NR) -> WebSocketConnector<C, H, NR, RNG, WB> {
WebSocketConnector {
compression: self.compression,
headers: self.headers,
no_masking: self.no_masking,
res: elem,
rng: self.rng,
wsb: self.wsb,
}
}
#[inline]
pub fn rng(mut self, elem: RNG) -> WebSocketConnector<C, H, R, RNG, WB> {
self.rng = elem;
self
}
#[inline]
pub fn wsb<NWSB>(self, elem: NWSB) -> WebSocketConnector<C, H, R, RNG, NWSB> {
WebSocketConnector {
compression: self.compression,
headers: self.headers,
no_masking: self.no_masking,
res: self.res,
rng: self.rng,
wsb: elem,
}
}
}
impl Default
for WebSocketConnector<
(),
IntoIter<(&'static str, &'static str), 0>,
fn(&Response<'_, '_>) -> crate::Result<()>,
Xorshift64,
WebSocketBuffer,
>
{
#[inline]
fn default() -> Self {
#[inline]
const fn res(_: &Response<'_, '_>) -> crate::Result<()> {
Ok(())
}
Self {
compression: (),
headers: [].into_iter(),
no_masking: true,
res,
rng: Xorshift64::from(simple_seed()),
wsb: WebSocketBuffer::new(),
}
}
}