krustie/server/
route_handler.rs

1use dyn_clone::{clone_trait_object, DynClone};
2
3use crate::{Request, Response};
4
5/// Route handler trait
6///
7/// This trait is used to define the handler for the routes and middlewares.
8pub trait RouteHandler: DynClone + Send {
9    /// Handles the request and returns the result of the handler. It is used to define the handler for the routes and middlewares.
10    fn handle(&mut self, request: &Request, response: &mut Response) -> HandlerResult;
11}
12
13#[derive(Debug, PartialEq, Eq)]
14/// Result of the handler
15///
16/// `End` - Stops the execution of the handler chain
17///
18/// `Next` - Continues the execution of the handler chain
19pub enum HandlerResult {
20    /// **Stops** the execution of the handler chain. And the response is sent to the client.
21    End,
22    /// **Continues** the execution of the handler chain.
23    Next,
24}
25
26clone_trait_object!(RouteHandler);