use std::{ops::Deref, sync::Arc}; use crate::server::config::ServerConfig; #[derive(Clone)] pub struct SharedState(Arc); impl SharedState { pub async fn new(config: ServerConfig) -> anyhow::Result { Ok(Self(Arc::new(State::new(config).await?))) } } impl From<&SharedState> for SharedState { fn from(value: &SharedState) -> Self { value.clone() } } impl Deref for SharedState { type Target = Arc; fn deref(&self) -> &Self::Target { &self.0 } } pub struct State { pub config: ServerConfig, } impl State { pub async fn new(config: ServerConfig) -> anyhow::Result { Ok(Self { config }) } }