1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
use hyper::method::Method;
use handlers;
use std::fmt;
use Path;
use Handler;
use super::RouteBuilder;
pub struct Route {
pub method: Method,
pub path: Path,
pub handler: Handler
}
impl Route {
pub fn get(path: &str) -> RouteBuilder {
Route::from(Method::Get, path)
}
pub fn post(path: &str) -> RouteBuilder {
Route::from(Method::Post, path)
}
pub fn put(path: &str) -> RouteBuilder {
Route::from(Method::Put, path)
}
pub fn delete(path: &str) -> RouteBuilder {
Route::from(Method::Delete, path)
}
pub fn patch(path: &str) -> RouteBuilder {
Route::from(Method::Patch, path)
}
pub fn from(method: Method, path: &str) -> RouteBuilder {
RouteBuilder::new(Route {
method: method,
path: Path::new(path),
.. Route::default()
})
}
}
impl Default for Route {
fn default() -> Route {
Route {
method: Method::Get,
path: Path::new("/"),
handler: handlers::not_implemented_handler
}
}
}
impl fmt::Debug for Route {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "Route {{method: {:?}, path: {:?}}}", self.method, self.path)
}
}