use {axum::extract::*, compris::normal::*, kutil::std::immutable::*};
#[derive(Clone, Debug)]
pub struct SocketMiddleware {
pub socket: Socket,
}
impl SocketMiddleware {
pub fn new(socket: Socket) -> Self {
Self { socket }
}
pub async fn function(State(state_self): State<Self>, mut request: Request) -> Request {
request.extensions_mut().insert(state_self.socket.clone());
request
}
}
#[derive(Clone, Debug)]
pub struct Socket {
pub port: u16,
pub tls: bool,
pub host: ByteString,
}
impl Socket {
pub fn new(port: u16, tls: bool, host: ByteString) -> Self {
Self { port, tls, host }
}
}
impl<AnnotatedT> Into<Variant<AnnotatedT>> for &Socket
where
AnnotatedT: Default,
{
fn into(self) -> Variant<AnnotatedT> {
let mut socket_map = Map::default();
socket_map.into_insert("port", self.port);
socket_map.into_insert("tls", self.tls);
socket_map.into_insert("host", self.host.clone());
socket_map.into()
}
}