Skip to main content

aver_rt/
service_types.rs

1use crate::{AverDisplay, AverList, AverMap, AverStr};
2
3#[derive(Clone, Debug, PartialEq, Eq, Hash, Ord, PartialOrd)]
4pub struct TerminalSize {
5    pub width: i64,
6    pub height: i64,
7}
8
9impl AverDisplay for TerminalSize {
10    fn aver_display(&self) -> String {
11        format!(
12            "Terminal.Size(width: {}, height: {})",
13            self.width.aver_display_inner(),
14            self.height.aver_display_inner()
15        )
16    }
17
18    fn aver_display_inner(&self) -> String {
19        self.aver_display()
20    }
21}
22
23/// Multi-value HTTP headers, modelled as `Map<String, List<String>>` —
24/// matches RFC 9110 (same-name fields) and RFC 6265 (multiple
25/// Set-Cookie). Keys are case-insensitive by convention; runtime
26/// lowercases incoming names. Mirrors Go `net/http.Header`.
27pub type HttpHeaders = AverMap<AverStr, AverList<AverStr>>;
28
29#[derive(Clone, Debug, PartialEq)]
30pub struct HttpResponse {
31    pub status: i64,
32    pub body: AverStr,
33    pub headers: HttpHeaders,
34}
35
36impl AverDisplay for HttpResponse {
37    fn aver_display(&self) -> String {
38        format!(
39            "HttpResponse(status: {}, body: {}, headers: {})",
40            self.status.aver_display_inner(),
41            self.body.aver_display_inner(),
42            self.headers.aver_display_inner()
43        )
44    }
45
46    fn aver_display_inner(&self) -> String {
47        self.aver_display()
48    }
49}
50
51#[derive(Clone, Debug, PartialEq)]
52pub struct HttpRequest {
53    pub method: AverStr,
54    pub path: AverStr,
55    pub body: AverStr,
56    pub headers: HttpHeaders,
57}
58
59impl AverDisplay for HttpRequest {
60    fn aver_display(&self) -> String {
61        format!(
62            "HttpRequest(method: {}, path: {}, body: {}, headers: {})",
63            self.method.aver_display_inner(),
64            self.path.aver_display_inner(),
65            self.body.aver_display_inner(),
66            self.headers.aver_display_inner()
67        )
68    }
69
70    fn aver_display_inner(&self) -> String {
71        self.aver_display()
72    }
73}
74
75#[derive(Clone, Debug, PartialEq, Eq, Hash, Ord, PartialOrd)]
76pub struct TcpConnection {
77    pub id: AverStr,
78    pub host: AverStr,
79    pub port: i64,
80}
81
82impl TcpConnection {
83    pub fn from_parts(id: String, host: String, port: i64) -> Self {
84        Self {
85            id: AverStr::from(id),
86            host: AverStr::from(host),
87            port,
88        }
89    }
90}
91
92impl AverDisplay for TcpConnection {
93    fn aver_display(&self) -> String {
94        format!(
95            "Tcp.Connection(id: {}, host: {}, port: {})",
96            self.id.aver_display_inner(),
97            self.host.aver_display_inner(),
98            self.port.aver_display_inner()
99        )
100    }
101
102    fn aver_display_inner(&self) -> String {
103        self.aver_display()
104    }
105}