diff options
| author | Fuwn <[email protected]> | 2023-04-04 09:12:11 +0000 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2023-04-04 09:12:11 +0000 |
| commit | bda843b8f911f379fd8d3af526b9e6619f6a5ca9 (patch) | |
| tree | e297caaf07d84f2ba9351cc440ffd0c1ec45aa69 /src/handler | |
| parent | feat(cargo): bump 0.2.5 -> 0.3.0 (diff) | |
| download | windmark-bda843b8f911f379fd8d3af526b9e6619f6a5ca9.tar.xz windmark-bda843b8f911f379fd8d3af526b9e6619f6a5ca9.zip | |
feat(route): native async route support !!
Diffstat (limited to 'src/handler')
| -rw-r--r-- | src/handler/response/route.rs | 24 |
1 files changed, 19 insertions, 5 deletions
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 <[email protected]> // 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<Box<dyn Future<Output = Response> + Send>>; } -impl<T> RouteResponse for T where T: FnMut(RouteContext<'_>) -> Response + Send + Sync -{} +impl<T, F> RouteResponse for T +where + T: FnMut(RouteContext<'_>) -> F + Send + Sync, + F: Future<Output = Response> + Send + 'static, +{ + fn call( + &mut self, + context: RouteContext<'_>, + ) -> Pin<Box<dyn Future<Output = Response> + Send>> { + Box::pin((*self)(context)) + } +} |