plane_common/
log_types.rs

1use chrono::{DateTime, Utc};
2use serde::{Deserialize, Serialize};
3use std::net::SocketAddr;
4use valuable::{Tuplable, TupleDef, Valuable, Value, Visit};
5
6// See: https://github.com/tokio-rs/valuable/issues/86#issuecomment-1760446976
7
8#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
9pub struct LoggableTime(#[serde(with = "chrono::serde::ts_milliseconds")] pub DateTime<Utc>);
10
11impl Valuable for LoggableTime {
12    fn as_value(&self) -> Value<'_> {
13        Value::Tuplable(self)
14    }
15
16    fn visit(&self, visit: &mut dyn Visit) {
17        let s: String = format!("{}", self.0);
18        let val = Value::String(s.as_str());
19        visit.visit_unnamed_fields(&[val]);
20    }
21}
22
23impl Tuplable for LoggableTime {
24    fn definition(&self) -> TupleDef {
25        TupleDef::new_static(1)
26    }
27}
28
29#[derive(Clone, Copy, Serialize, Deserialize, Debug, PartialEq, Eq, PartialOrd)]
30pub struct BackendAddr(pub SocketAddr);
31
32impl valuable::Valuable for BackendAddr {
33    fn as_value(&self) -> valuable::Value {
34        Value::Tuplable(self)
35    }
36
37    fn visit(&self, visit: &mut dyn valuable::Visit) {
38        let s: String = format!("{:?}", self.0);
39        let val = valuable::Value::String(s.as_str());
40        visit.visit_unnamed_fields(&[val]);
41    }
42}
43
44impl Tuplable for BackendAddr {
45    fn definition(&self) -> valuable::TupleDef {
46        valuable::TupleDef::new_static(1)
47    }
48}