From 4ca0c24b1989fcd12c453d428af70f58456f7651 Mon Sep 17 00:00:00 2001 From: Vika Date: Thu, 1 Aug 2024 20:01:12 +0300 Subject: Migrate from axum::Extension to axum::extract::State This somehow allowed me to shrink the construction phase of Kittybox by a huge amount of code. --- src/frontend/onboarding.rs | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) (limited to 'src/frontend/onboarding.rs') diff --git a/src/frontend/onboarding.rs b/src/frontend/onboarding.rs index faf8cdd..9f3f36b 100644 --- a/src/frontend/onboarding.rs +++ b/src/frontend/onboarding.rs @@ -2,7 +2,7 @@ use std::sync::Arc; use crate::database::{settings, Storage}; use axum::{ - extract::{Extension, Host}, + extract::{FromRef, Host, State}, http::StatusCode, response::{Html, IntoResponse}, Json, @@ -131,10 +131,10 @@ async fn onboard( } pub async fn post( - Extension(db): Extension, + State(db): State, Host(host): Host, - Extension(http): Extension, - Extension(jobset): Extension>>>, + State(http): State, + State(jobset): State>>>, Json(data): Json, ) -> axum::response::Response { let user_uid = format!("https://{}/", host.as_str()); @@ -168,14 +168,13 @@ pub async fn post( } } -pub fn router( - database: S, - http: reqwest::Client, - jobset: Arc>>, -) -> axum::routing::MethodRouter { +pub fn router() -> axum::routing::MethodRouter +where + S: Storage + FromRef + 'static, + Arc>>: FromRef, + reqwest::Client: FromRef, + St: Clone + Send + Sync + 'static, +{ axum::routing::get(get) .post(post::) - .layer::<_, _, std::convert::Infallible>(axum::Extension(database)) - .layer::<_, _, std::convert::Infallible>(axum::Extension(http)) - .layer(axum::Extension(jobset)) } -- cgit 1.4.1