use std::net::SocketAddr;
use trillium_http::{HttpConfig, HttpContext, Swansong, TypeSet, type_set::entry::Entry};
#[derive(Debug, Default)]
pub struct Info(HttpContext);
impl From<HttpContext> for Info {
fn from(value: HttpContext) -> Self {
Self(value)
}
}
impl From<Info> for HttpContext {
fn from(value: Info) -> Self {
value.0
}
}
impl AsRef<TypeSet> for Info {
fn as_ref(&self) -> &TypeSet {
self.0.as_ref()
}
}
impl AsMut<TypeSet> for Info {
fn as_mut(&mut self) -> &mut TypeSet {
self.0.as_mut()
}
}
impl Info {
pub fn tcp_socket_addr(&self) -> Option<&SocketAddr> {
self.shared_state()
}
#[cfg(unix)]
pub fn unix_socket_addr(&self) -> Option<&std::os::unix::net::SocketAddr> {
self.shared_state()
}
pub fn shared_state<T: Send + Sync + 'static>(&self) -> Option<&T> {
self.0.shared_state().get()
}
pub fn insert_shared_state<T: Send + Sync + 'static>(&mut self, value: T) -> Option<T> {
self.0.shared_state_mut().insert(value)
}
pub fn shared_state_mut<T: Send + Sync + 'static>(&mut self) -> Option<&mut T> {
self.0.shared_state_mut().get_mut()
}
pub fn shared_state_entry<T: Send + Sync + 'static>(&mut self) -> Entry<'_, T> {
self.0.shared_state_mut().entry()
}
#[must_use]
pub fn with_shared_state<T: Send + Sync + 'static>(mut self, value: T) -> Self {
self.insert_shared_state(value);
self
}
pub fn config(&self) -> &HttpConfig {
self.0.config()
}
pub fn config_mut(&mut self) -> &mut HttpConfig {
self.0.config_mut()
}
pub fn swansong(&self) -> &Swansong {
self.0.swansong()
}
}