zino_http/timing/
server_timing.rs1use super::TimingMetric;
2use smallvec::SmallVec;
3use std::fmt;
4
5#[derive(Debug, Clone)]
8pub struct ServerTiming {
9 metrics: SmallVec<[TimingMetric; 4]>,
11}
12
13impl ServerTiming {
14 #[inline]
16 pub fn new() -> Self {
17 Self {
18 metrics: SmallVec::new(),
19 }
20 }
21
22 #[inline]
24 pub fn push(&mut self, metric: TimingMetric) {
25 self.metrics.push(metric);
26 }
27}
28
29impl Default for ServerTiming {
30 fn default() -> Self {
31 Self::new()
32 }
33}
34
35impl fmt::Display for ServerTiming {
36 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
37 let output = self
38 .metrics
39 .iter()
40 .map(|metric| metric.to_string())
41 .collect::<Vec<_>>()
42 .join(", ");
43 write!(f, "{output}")
44 }
45}