1use super::application::{Context, Handler};
2
3pub struct Router<'a> {
4 pub prefix: &'a str,
5 pub layers: Vec<Handler>,
6}
7
8impl<'a> Router<'a> {
9 pub fn new(prefix: &'a str) -> Self {
10 Router {
11 prefix,
12 layers: vec![],
13 }
14 }
15
16 pub fn get(&mut self, path: &'a str, func: fn(&mut Context, &mut dyn FnMut(&mut Context))) {
17 &self.layers.push(Handler {
18 method: "GET".to_string(),
19 path: path.to_string(),
20 func: func,
21 });
22 }
23
24 pub fn post(&mut self, path: &'a str, func: fn(&mut Context, &mut dyn FnMut(&mut Context))) {
25 &self.layers.push(Handler {
26 method: "POST".to_string(),
27 path: path.to_string(),
28 func: func,
29 });
30 }
31
32 pub fn hold(&mut self, path: &'a str, func: fn(&mut Context, &mut dyn FnMut(&mut Context))) {
33 &self.layers.push(Handler {
34 method: "ALL".to_string(),
35 path: path.to_string(),
36 func: func,
37 });
38 }
39}