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
use tide::http::Method;
use tide::{Endpoint, Middleware};
pub trait RouteBuilder<State: Clone + Send + Sync + 'static>: Sized {
fn at<R: Fn(Self) -> Self>(self, path: &str, routes: R) -> Self;
fn with<M: Middleware<State>, R: Fn(Self) -> Self>(self, middleware: M, routes: R) -> Self;
fn method(self, method: Method, endpoint: impl Endpoint<State>) -> Self;
fn all(self, endpoint: impl Endpoint<State>) -> Self;
}
pub trait RouteBuilderExt<State: Clone + Send + Sync + 'static>: RouteBuilder<State> {
fn get(self, endpoint: impl Endpoint<State>) -> Self {
self.method(Method::Get, endpoint)
}
fn head(self, endpoint: impl Endpoint<State>) -> Self {
self.method(Method::Head, endpoint)
}
fn put(self, endpoint: impl Endpoint<State>) -> Self {
self.method(Method::Put, endpoint)
}
fn post(self, endpoint: impl Endpoint<State>) -> Self {
self.method(Method::Post, endpoint)
}
fn delete(self, endpoint: impl Endpoint<State>) -> Self {
self.method(Method::Delete, endpoint)
}
fn options(self, endpoint: impl Endpoint<State>) -> Self {
self.method(Method::Options, endpoint)
}
fn connect(self, endpoint: impl Endpoint<State>) -> Self {
self.method(Method::Connect, endpoint)
}
fn patch(self, endpoint: impl Endpoint<State>) -> Self {
self.method(Method::Patch, endpoint)
}
fn trace(self, endpoint: impl Endpoint<State>) -> Self {
self.method(Method::Trace, endpoint)
}
}
impl<State: Clone + Send + Sync + 'static, R: RouteBuilder<State>> RouteBuilderExt<State> for R {}