From bda843b8f911f379fd8d3af526b9e6619f6a5ca9 Mon Sep 17 00:00:00 2001 From: Fuwn Date: Tue, 4 Apr 2023 09:12:11 +0000 Subject: feat(route): native async route support !! --- src/handler/response/route.rs | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) (limited to 'src/handler') diff --git a/src/handler/response/route.rs b/src/handler/response/route.rs index f480b02..91265a3 100644 --- a/src/handler/response/route.rs +++ b/src/handler/response/route.rs @@ -16,13 +16,27 @@ // Copyright (C) 2022-2022 Fuwn // SPDX-License-Identifier: GPL-3.0-only +use std::{future::Future, pin::Pin}; + use crate::{context::RouteContext, Response}; #[allow(clippy::module_name_repetitions)] -pub trait RouteResponse: - FnMut(RouteContext<'_>) -> Response + Send + Sync -{ +pub trait RouteResponse: Send + Sync { + fn call( + &mut self, + context: RouteContext<'_>, + ) -> Pin + Send>>; } -impl RouteResponse for T where T: FnMut(RouteContext<'_>) -> Response + Send + Sync -{} +impl RouteResponse for T +where + T: FnMut(RouteContext<'_>) -> F + Send + Sync, + F: Future + Send + 'static, +{ + fn call( + &mut self, + context: RouteContext<'_>, + ) -> Pin + Send>> { + Box::pin((*self)(context)) + } +} -- cgit v1.2.3