From 0bfd57be84b7cfe11e5181222ba6018e668d63c9 Mon Sep 17 00:00:00 2001 From: Fuwn Date: Mon, 3 Apr 2023 02:52:18 +0000 Subject: refactor(handler): move all responses to traits --- src/handler.rs | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'src/handler.rs') diff --git a/src/handler.rs b/src/handler.rs index b283cdf..88dafc8 100644 --- a/src/handler.rs +++ b/src/handler.rs @@ -38,7 +38,18 @@ pub trait ErrorResponse: impl ErrorResponse for T where T: FnMut(returnable::ErrorContext<'_>) -> Response + Send + Sync {} -pub type Callback = Box) + Send + Sync>; -pub type CleanupCallback = - Box, &mut Response) + Send + Sync>; -pub type Partial = Box) -> String + Send + Sync>; +pub trait Callback: FnMut(CallbackContext<'_>) + Send + Sync {} + +impl Callback for T where T: FnMut(CallbackContext<'_>) + Send + Sync {} + +pub trait CleanupCallback: + FnMut(CallbackContext<'_>, &mut Response) + Send + Sync +{ +} + +impl CleanupCallback for T where T: FnMut(CallbackContext<'_>, &mut Response) + Send + Sync +{} + +pub trait Partial: FnMut(RouteContext<'_>) -> String + Send + Sync {} + +impl Partial for T where T: FnMut(RouteContext<'_>) -> String + Send + Sync {} -- cgit v1.2.3