diff options
| author | Fuwn <[email protected]> | 2023-04-03 02:52:18 +0000 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2023-04-03 02:52:18 +0000 |
| commit | 0bfd57be84b7cfe11e5181222ba6018e668d63c9 (patch) | |
| tree | c9a8fec6a65718bf4504911c38942a3ce98698af /src/handler.rs | |
| parent | refactor(handler): trait-based response (diff) | |
| download | windmark-0bfd57be84b7cfe11e5181222ba6018e668d63c9.tar.xz windmark-0bfd57be84b7cfe11e5181222ba6018e668d63c9.zip | |
refactor(handler): move all responses to traits
Diffstat (limited to 'src/handler.rs')
| -rw-r--r-- | src/handler.rs | 19 |
1 files changed, 15 insertions, 4 deletions
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<T> ErrorResponse for T where T: FnMut(returnable::ErrorContext<'_>) -> Response + Send + Sync {} -pub type Callback = Box<dyn FnMut(CallbackContext<'_>) + Send + Sync>; -pub type CleanupCallback = - Box<dyn FnMut(CallbackContext<'_>, &mut Response) + Send + Sync>; -pub type Partial = Box<dyn FnMut(RouteContext<'_>) -> String + Send + Sync>; +pub trait Callback: FnMut(CallbackContext<'_>) + Send + Sync {} + +impl<T> Callback for T where T: FnMut(CallbackContext<'_>) + Send + Sync {} + +pub trait CleanupCallback: + FnMut(CallbackContext<'_>, &mut Response) + Send + Sync +{ +} + +impl<T> CleanupCallback for T where T: FnMut(CallbackContext<'_>, &mut Response) + Send + Sync +{} + +pub trait Partial: FnMut(RouteContext<'_>) -> String + Send + Sync {} + +impl<T> Partial for T where T: FnMut(RouteContext<'_>) -> String + Send + Sync {} |