hyper_router/route/
route_impl.rs1use crate::handlers;
2use hyper::Method;
3use std::fmt;
4
5use super::RouteBuilder;
6use crate::Handler;
7use crate::Path;
8
9pub struct Route {
11 pub method: Method,
13
14 pub path: Path,
16
17 pub handler: Handler,
34}
35
36impl Route {
37 pub fn options(path: &str) -> RouteBuilder {
38 Route::from(Method::OPTIONS, path)
39 }
40
41 pub fn get(path: &str) -> RouteBuilder {
42 Route::from(Method::GET, path)
43 }
44
45 pub fn post(path: &str) -> RouteBuilder {
46 Route::from(Method::POST, path)
47 }
48
49 pub fn put(path: &str) -> RouteBuilder {
50 Route::from(Method::PUT, path)
51 }
52
53 pub fn delete(path: &str) -> RouteBuilder {
54 Route::from(Method::DELETE, path)
55 }
56
57 pub fn head(path: &str) -> RouteBuilder {
58 Route::from(Method::HEAD, path)
59 }
60
61 pub fn trace(path: &str) -> RouteBuilder {
62 Route::from(Method::TRACE, path)
63 }
64
65 pub fn connect(path: &str) -> RouteBuilder {
66 Route::from(Method::CONNECT, path)
67 }
68
69 pub fn patch(path: &str) -> RouteBuilder {
70 Route::from(Method::PATCH, path)
71 }
72
73 pub fn from(method: Method, path: &str) -> RouteBuilder {
74 RouteBuilder::new(Route {
75 method,
76 path: Path::new(path),
77 ..Route::default()
78 })
79 }
80}
81
82impl Default for Route {
83 fn default() -> Route {
84 Route {
85 method: Method::GET,
86 path: Path::new("/"),
87 handler: handlers::not_implemented_handler,
88 }
89 }
90}
91
92impl fmt::Debug for Route {
93 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
94 write!(
95 f,
96 "Route {{method: {:?}, path: {:?}}}",
97 self.method, self.path
98 )
99 }
100}