From 8a6751398d7e9ea5cf28d48992bae99541431cd6 Mon Sep 17 00:00:00 2001 From: Quentin Gliech Date: Mon, 22 Nov 2021 19:03:59 +0100 Subject: [PATCH] Use BoxedFilter on main handlers to reduce compile times This avoids having opaque `impl Filter`, which moves the compile time in the `core` crate instead of the end `cli` one --- crates/core/src/handlers/health.rs | 7 +++---- crates/core/src/handlers/mod.rs | 5 +++-- crates/core/src/handlers/oauth2/mod.rs | 5 +++-- crates/core/src/handlers/views/mod.rs | 4 ++-- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/crates/core/src/handlers/health.rs b/crates/core/src/handlers/health.rs index f5697ef0..11799b0a 100644 --- a/crates/core/src/handlers/health.rs +++ b/crates/core/src/handlers/health.rs @@ -16,17 +16,16 @@ use hyper::header::CONTENT_TYPE; use mime::TEXT_PLAIN; use sqlx::{pool::PoolConnection, PgPool, Postgres}; use tracing::{info_span, Instrument}; -use warp::{reply::with_header, Filter, Rejection, Reply}; +use warp::{filters::BoxedFilter, reply::with_header, Filter, Rejection, Reply}; use crate::{errors::WrapError, filters::database::connection}; -pub fn filter( - pool: &PgPool, -) -> impl Filter + Clone + Send + Sync + 'static { +pub fn filter(pool: &PgPool) -> BoxedFilter<(impl Reply,)> { warp::path!("health") .and(warp::get()) .and(connection(pool)) .and_then(get) + .boxed() } async fn get(mut conn: PoolConnection) -> Result { diff --git a/crates/core/src/handlers/mod.rs b/crates/core/src/handlers/mod.rs index e1ca00cf..4ae0090a 100644 --- a/crates/core/src/handlers/mod.rs +++ b/crates/core/src/handlers/mod.rs @@ -16,7 +16,7 @@ use mas_templates::Templates; use sqlx::PgPool; -use warp::{Filter, Rejection, Reply}; +use warp::{filters::BoxedFilter, Filter, Reply}; use crate::config::RootConfig; @@ -31,7 +31,7 @@ pub fn root( pool: &PgPool, templates: &Templates, config: &RootConfig, -) -> impl Filter + Clone + Send + Sync + 'static { +) -> BoxedFilter<(impl Reply,)> { health(pool) .or(oauth2(pool, templates, &config.oauth2, &config.cookies)) .or(views( @@ -42,4 +42,5 @@ pub fn root( &config.cookies, )) .with(warp::log(module_path!())) + .boxed() } diff --git a/crates/core/src/handlers/oauth2/mod.rs b/crates/core/src/handlers/oauth2/mod.rs index 03205478..19b771b6 100644 --- a/crates/core/src/handlers/oauth2/mod.rs +++ b/crates/core/src/handlers/oauth2/mod.rs @@ -14,7 +14,7 @@ use mas_templates::Templates; use sqlx::PgPool; -use warp::{Filter, Rejection, Reply}; +use warp::{filters::BoxedFilter, Filter, Reply}; use crate::config::{CookiesConfig, OAuth2Config}; @@ -37,7 +37,7 @@ pub fn filter( templates: &Templates, oauth2_config: &OAuth2Config, cookies_config: &CookiesConfig, -) -> impl Filter + Clone + Send + Sync + 'static { +) -> BoxedFilter<(impl Reply,)> { discovery(oauth2_config) .or(keys(oauth2_config)) .or(authorization( @@ -49,4 +49,5 @@ pub fn filter( .or(userinfo(pool, oauth2_config)) .or(introspection(pool, oauth2_config)) .or(token(pool, oauth2_config)) + .boxed() } diff --git a/crates/core/src/handlers/views/mod.rs b/crates/core/src/handlers/views/mod.rs index a452f78b..293dbc79 100644 --- a/crates/core/src/handlers/views/mod.rs +++ b/crates/core/src/handlers/views/mod.rs @@ -14,7 +14,7 @@ use mas_templates::Templates; use sqlx::PgPool; -use warp::{Filter, Rejection, Reply}; +use warp::{filters::BoxedFilter, Filter, Reply}; use crate::config::{CookiesConfig, CsrfConfig, OAuth2Config}; @@ -37,7 +37,7 @@ pub(super) fn filter( oauth2_config: &OAuth2Config, csrf_config: &CsrfConfig, cookies_config: &CookiesConfig, -) -> impl Filter + Clone + Send + Sync + 'static { +) -> BoxedFilter<(impl Reply,)> { index(pool, templates, oauth2_config, csrf_config, cookies_config) .or(login(pool, templates, csrf_config, cookies_config)) .or(register(pool, templates, csrf_config, cookies_config))