rust_api_kit/http/client/
macros.rs1#[macro_export]
2macro_rules! define_http_routes {
3 (
4 $(
5 group (
6 path $path_prefix:literal;
7 $(auth $auth_ty:ty;)?
8 error $unexpected:ty;
9
10 $(
11 $method:ident $path:literal $req:ty => $res:ty | $err:ty;
12 )*
13 );
14 )*
15 ) => {
16 $(
17 $crate::define_http_routes!(@impl_group $(auth $auth_ty;)? $unexpected; $path_prefix; $(($method, $path, $req, $res, $err))*);
18 )*
19 };
20
21 (@impl_group auth $auth_ty:ty; $unexpected:ty; $path_prefix:literal; $(($method:ident, $path:literal, $req:ty, $res:ty, $err:ty))*) => {
22 $(
23 impl $crate::http::client::HttpRequest<$res, $err, $unexpected> for $req {
24 const ENDPOINT: &'static str = concat!("/", $path_prefix, "/", $path);
25 const METHOD: $crate::http::client::RequestMethod = $crate::http::client::RequestMethod::$method;
26 }
27
28 impl Into<$crate::http::client::Response<$res, $err, $unexpected>> for $res
29 {
30 fn into(
31 self,
32 ) -> $crate::http::client::Response<$res, $err, $unexpected>
33 {
34 $crate::http::client::Response::Ok(self)
35 }
36 }
37
38 impl Into<$crate::http::client::Response<$res, $err,$unexpected>> for $err
39 {
40 fn into(
41 self,
42 ) -> $crate::http::client::Response<$res, $err,$unexpected>
43 {
44 $crate::http::client::Response::Error(self)
45 }
46 }
47
48 impl Into<$crate::http::client::Response<$res, $err, $unexpected>> for $unexpected
49 {
50 fn into(
51 self,
52 ) -> $crate::http::client::Response<$res, $err, $unexpected>
53 {
54 $crate::http::client::Response::UnexpectedError(self)
55 }
56 }
57
58
59 impl $crate::http::client::AuthenticatedHttpRequest<$auth_ty> for $req {}
60 )*
61 };
62
63 (@impl_group $unexpected:ty; $path_prefix:literal; $(($method:ident, $path:literal, $req:ty, $res:ty, $err:ty))*) => {
64 $(
65 impl $crate::http::client::HttpRequest<$res, $err, $unexpected> for $req {
66 const ENDPOINT: &'static str = concat!("/", $path_prefix, "/", $path);
67 const METHOD: $crate::http::client::RequestMethod = $crate::http::client::RequestMethod::$method;
68 }
69
70 impl Into<$crate::http::client::Response<$res, $err, $unexpected>> for $res
71 {
72 fn into(
73 self,
74 ) -> $crate::http::client::Response<$res, $err, $unexpected>
75 {
76 $crate::http::client::Response::Ok(self)
77 }
78 }
79
80 impl Into<$crate::http::client::Response<$res, $err,$unexpected>> for $err
81 {
82 fn into(
83 self,
84 ) -> $crate::http::client::Response<$res, $err,$unexpected>
85 {
86 $crate::http::client::Response::Error(self)
87 }
88 }
89
90 impl Into<$crate::http::client::Response<$res, $err, $unexpected>> for $unexpected
91 {
92 fn into(
93 self,
94 ) -> $crate::http::client::Response<$res, $err, $unexpected>
95 {
96 $crate::http::client::Response::UnexpectedError(self)
97 }
98 }
99 )*
100 };
101}