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
use serde::{Deserialize, Serialize};
#[macro_export]
macro_rules! log_serde {
($response:ident $type_name:tt) => {
log::as_serde!($crate::helpers::log::$type_name::from(&$response))
};
}
#[derive(Debug, Copy, Clone, Serialize, Deserialize)]
pub struct Status {
pub code: u16,
pub message: Option<&'static str>,
}
impl Status {
pub fn new(status: reqwest::StatusCode) -> Self {
Self {
code: status.as_u16(),
message: status.canonical_reason(),
}
}
}
impl From<&reqwest::Response> for Status {
fn from(value: &reqwest::Response) -> Self {
Self::new(value.status())
}
}
#[derive(Debug)]
pub struct Headers(pub reqwest::header::HeaderMap);
impl Serialize for Headers {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
serializer.collect_map(
self.0
.iter()
.map(|(k, v)| (format!("{k:?}"), format!("{v:?}"))),
)
}
}
impl From<&reqwest::Response> for Headers {
fn from(value: &reqwest::Response) -> Self {
Headers(value.headers().clone())
}
}