diff --git a/src/api/mod.rs b/src/api/mod.rs index 7fa70873..00ae35cd 100644 --- a/src/api/mod.rs +++ b/src/api/mod.rs @@ -10,8 +10,8 @@ extern crate conduit_service as service; pub(crate) use conduit::{debug_info, pdu::PduEvent, utils, Error, Result}; pub(crate) use service::services; -pub use crate::router::State; -pub(crate) use crate::router::{Ruma, RumaResponse}; +pub use self::router::State; +pub(crate) use self::router::{Ruma, RumaResponse}; conduit::mod_ctor! {} conduit::mod_dtor! {} diff --git a/src/api/router.rs b/src/api/router.rs index d624de32..cff58c32 100644 --- a/src/api/router.rs +++ b/src/api/router.rs @@ -3,8 +3,7 @@ mod auth; mod handler; mod request; mod response; - -use std::sync::Arc; +mod state; use axum::{ response::IntoResponse, @@ -15,11 +14,10 @@ use conduit::{err, Server}; use http::Uri; use self::handler::RouterExt; +pub use self::state::State; pub(super) use self::{args::Args as Ruma, response::RumaResponse}; use crate::{client, server}; -pub type State = Arc; - pub fn build(router: Router, server: &Server) -> Router { let config = &server.config; let router = router diff --git a/src/api/router/state.rs b/src/api/router/state.rs new file mode 100644 index 00000000..b1149d89 --- /dev/null +++ b/src/api/router/state.rs @@ -0,0 +1,22 @@ +use std::{ops::Deref, sync::Arc}; + +use conduit_service::Services; + +#[derive(Clone)] +pub struct State { + services: Arc, +} + +impl State { + pub fn new(services: Arc) -> Self { + Self { + services, + } + } +} + +impl Deref for State { + type Target = Arc; + + fn deref(&self) -> &Self::Target { &self.services } +} diff --git a/src/router/router.rs b/src/router/router.rs index 3527f1e6..e59b088b 100644 --- a/src/router/router.rs +++ b/src/router/router.rs @@ -9,7 +9,7 @@ use ruma::api::client::error::ErrorKind; pub(crate) fn build(services: &Arc) -> Router { let router = Router::::new(); - let state = services.clone(); + let state = State::new(services.clone()); conduit_api::router::build(router, &services.server) .route("/", get(it_works))