All checks were successful
continuous-integration/drone/push Build is passing
Signed-off-by: kjuulh <contact@kjuulh.io>
37 lines
692 B
Rust
37 lines
692 B
Rust
use std::{ops::Deref, sync::Arc};
|
|
|
|
use crate::server::config::ServerConfig;
|
|
|
|
#[derive(Clone)]
|
|
pub struct SharedState(Arc<State>);
|
|
|
|
impl SharedState {
|
|
pub async fn new(config: ServerConfig) -> anyhow::Result<Self> {
|
|
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<State>;
|
|
|
|
fn deref(&self) -> &Self::Target {
|
|
&self.0
|
|
}
|
|
}
|
|
|
|
pub struct State {
|
|
pub config: ServerConfig,
|
|
}
|
|
|
|
impl State {
|
|
pub async fn new(config: ServerConfig) -> anyhow::Result<Self> {
|
|
Ok(Self { config })
|
|
}
|
|
}
|