pillow_http/
controller.rs1use super::{request::Request, response::Response};
2
3type ControllerBoxType = Box<dyn Fn(&Request) -> Response + Sync + Send + 'static>;
4
5pub trait ControllerT {
6 fn controller(&self, _: Request) -> Response;
7}
8
9pub struct Controller {
11 call_back: ControllerBoxType,
12}
13
14impl Controller {
15 pub fn new<F>(cb: F) -> Controller
17 where
18 F: Fn(&Request) -> Response + Sync + Send + 'static,
19 {
20 let action = Box::new(cb);
21
22 Controller { call_back: action }
23 }
24}
25
26impl Controller {
27 pub fn get_action(&self) -> &ControllerBoxType {
29 &self.call_back
30 }
31
32 pub fn use_action(&self, request: &Request) -> Response {
38 let cb = &self.get_action();
39
40 cb(request)
41 }
42}