add formal wrapping for api state

Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
Jason Volk 2024-07-28 21:31:35 +00:00
parent 5c258f41c8
commit ccef1a4c8b
4 changed files with 27 additions and 7 deletions

View File

@ -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! {}

View File

@ -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<service::Services>;
pub fn build(router: Router<State>, server: &Server) -> Router<State> {
let config = &server.config;
let router = router

22
src/api/router/state.rs Normal file
View File

@ -0,0 +1,22 @@
use std::{ops::Deref, sync::Arc};
use conduit_service::Services;
#[derive(Clone)]
pub struct State {
services: Arc<Services>,
}
impl State {
pub fn new(services: Arc<Services>) -> Self {
Self {
services,
}
}
}
impl Deref for State {
type Target = Arc<Services>;
fn deref(&self) -> &Self::Target { &self.services }
}

View File

@ -9,7 +9,7 @@ use ruma::api::client::error::ErrorKind;
pub(crate) fn build(services: &Arc<Services>) -> Router {
let router = Router::<State>::new();
let state = services.clone();
let state = State::new(services.clone());
conduit_api::router::build(router, &services.server)
.route("/", get(it_works))