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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
use std::borrow::Cow;
use serde::{ Serialize, Deserialize };
use reqwest::{ Method, header::HeaderMap };
pub use submit::*;
pub use status::*;
pub use result::*;
pub mod submit;
pub mod status;
pub mod result;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum RequestBody<T> {
None,
Json(T),
Query(T),
Form(T),
Multipart(T),
}
impl<T> Default for RequestBody<T> {
fn default() -> Self {
RequestBody::None
}
}
pub trait Request {
type Body: Serialize;
type Response: for<'de> Deserialize<'de>;
const METHOD: Method = Method::GET;
fn endpoint(&self) -> Cow<str>;
fn headers(&self) -> HeaderMap {
Default::default()
}
fn body(&self) -> RequestBody<&Self::Body> {
Default::default()
}
}
impl<R: Request> Request for &R {
type Body = R::Body;
type Response = R::Response;
const METHOD: Method = R::METHOD;
fn endpoint(&self) -> Cow<str> {
(**self).endpoint()
}
fn headers(&self) -> HeaderMap {
(**self).headers()
}
fn body(&self) -> RequestBody<&Self::Body> {
(**self).body()
}
}
impl<R: Request> Request for &mut R {
type Body = R::Body;
type Response = R::Response;
const METHOD: Method = R::METHOD;
fn endpoint(&self) -> Cow<str> {
(**self).endpoint()
}
fn headers(&self) -> HeaderMap {
(**self).headers()
}
fn body(&self) -> RequestBody<&Self::Body> {
(**self).body()
}
}