mastodon_async/helpers/
log.rs1use serde::{Deserialize, Serialize};
2
3#[macro_export]
17macro_rules! log_serde {
18 ($response:ident $type_name:tt) => {
19 log::as_serde!($crate::helpers::log::$type_name::from(&$response))
20 };
21}
22
23#[derive(Debug, Copy, Clone, Serialize, Deserialize)]
25pub struct Status {
26 pub code: u16,
28 pub message: Option<&'static str>,
30}
31
32impl Status {
33 pub fn new(status: reqwest::StatusCode) -> Self {
36 Self {
37 code: status.as_u16(),
38 message: status.canonical_reason(),
39 }
40 }
41}
42
43impl From<&reqwest::Response> for Status {
44 fn from(value: &reqwest::Response) -> Self {
45 Self::new(value.status())
46 }
47}
48
49#[derive(Debug)]
51pub struct Headers<'h>(pub &'h reqwest::header::HeaderMap);
52
53impl<'h> Serialize for Headers<'h> {
54 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
55 where
56 S: serde::Serializer,
57 {
58 serializer.collect_map(
59 self.0
60 .iter()
61 .map(|(k, v)| (format!("{k:?}"), format!("{v:?}"))),
62 )
63 }
64}
65
66impl<'h> From<&'h reqwest::Response> for Headers<'h> {
67 fn from(value: &'h reqwest::Response) -> Self {
68 Headers(value.headers())
69 }
70}