summaryrefslogtreecommitdiff
path: root/src/setup/required.rs
diff options
context:
space:
mode:
authorOwen Jacobson <owen@grimoire.ca>2025-10-28 14:41:50 -0400
committerOwen Jacobson <owen@grimoire.ca>2025-10-28 14:41:50 -0400
commit4a91792e023a5877f8ac9b8a352e99c4486d698f (patch)
tree0b0e5466d0945a5f853e98eb8d0b0215e67ed3fb /src/setup/required.rs
parent9c271b27ff03cf4976326090ff54e3b5dfc04962 (diff)
parent0ef69c7d256380e660edc45ace7f1d6151226340 (diff)
Merge remote-tracking branch 'codeberg/main' into push-notify
Diffstat (limited to 'src/setup/required.rs')
-rw-r--r--src/setup/required.rs31
1 files changed, 18 insertions, 13 deletions
diff --git a/src/setup/required.rs b/src/setup/required.rs
index a2aed18..e475381 100644
--- a/src/setup/required.rs
+++ b/src/setup/required.rs
@@ -4,26 +4,29 @@ use std::{
};
use axum::{
- extract::Request,
+ extract::{FromRef, Request},
http::StatusCode,
response::{IntoResponse, Response},
};
use tower::{Layer, Service};
-use crate::{app::App, error::Internal};
+use crate::{error::Internal, setup::app::Setup};
#[derive(Clone)]
-pub struct Required(pub App);
+pub struct Required<App>(pub App);
-impl Required {
- pub fn with_fallback<F>(self, fallback: F) -> WithFallback<F> {
+impl<App> Required<App> {
+ pub fn with_fallback<F>(self, fallback: F) -> WithFallback<App, F> {
let Self(app) = self;
WithFallback { app, fallback }
}
}
-impl<S> Layer<S> for Required {
- type Service = Middleware<S, Unavailable>;
+impl<S, App> Layer<S> for Required<App>
+where
+ Self: Clone,
+{
+ type Service = Middleware<S, App, Unavailable>;
fn layer(&self, inner: S) -> Self::Service {
let Self(app) = self.clone();
@@ -36,16 +39,16 @@ impl<S> Layer<S> for Required {
}
#[derive(Clone)]
-pub struct WithFallback<F> {
+pub struct WithFallback<App, F> {
app: App,
fallback: F,
}
-impl<S, F> Layer<S> for WithFallback<F>
+impl<S, App, F> Layer<S> for WithFallback<App, F>
where
Self: Clone,
{
- type Service = Middleware<S, F>;
+ type Service = Middleware<S, App, F>;
fn layer(&self, inner: S) -> Self::Service {
let Self { app, fallback } = self.clone();
@@ -58,17 +61,19 @@ where
}
#[derive(Clone)]
-pub struct Middleware<S, F> {
+pub struct Middleware<S, App, F> {
inner: S,
app: App,
fallback: F,
}
-impl<S, F> Service<Request> for Middleware<S, F>
+impl<S, App, F> Service<Request> for Middleware<S, App, F>
where
+ Setup: FromRef<App>,
Self: Clone,
S: Service<Request, Response = Response> + Send + 'static,
S::Future: Send,
+ App: Send + 'static,
F: IntoResponse + Clone + Send + 'static,
{
type Response = S::Response;
@@ -87,7 +92,7 @@ where
} = self.clone();
Box::pin(async move {
- match app.setup().completed().await {
+ match Setup::from_ref(&app).completed().await {
Ok(true) => inner.call(req).await,
Ok(false) => Ok(fallback.into_response()),
Err(error) => Ok(Internal::from(error).into_response()),