transport: derive Serialize for EthernetStatsSnapshot

EthernetStatsSnapshot derived only Clone/Debug/Default, unlike every
other transport's *StatsSnapshot which also derives Serialize. That gap
forced a hand-rolled serde_json::json!{} arm in TransportHandle::
transport_stats() that re-listed all ten fields by hand. Add the
Serialize derive and collapse the arm to the same one-line
serde_json::to_value(...) form the other transports use. The emitted
JSON keys and values are unchanged.
This commit is contained in:
Johnathan Corgan
2026-07-11 04:27:50 +00:00
parent 8aab71af86
commit a7dfe47663
2 changed files with 4 additions and 14 deletions
+3 -1
View File
@@ -2,6 +2,8 @@
use portable_atomic::{AtomicU64, Ordering};
use serde::Serialize;
/// Statistics for an Ethernet transport instance.
///
/// Uses atomic counters for lock-free updates from the receive loop
@@ -92,7 +94,7 @@ impl Default for EthernetStats {
}
/// Point-in-time snapshot of Ethernet stats (non-atomic, copyable).
#[derive(Clone, Debug, Default)]
#[derive(Clone, Debug, Default, Serialize)]
pub struct EthernetStatsSnapshot {
pub frames_sent: u64,
pub frames_recv: u64,
+1 -13
View File
@@ -1022,19 +1022,7 @@ impl TransportHandle {
}
#[cfg(unix)]
TransportHandle::Ethernet(t) => {
let snap = t.stats().snapshot();
serde_json::json!({
"frames_sent": snap.frames_sent,
"frames_recv": snap.frames_recv,
"bytes_sent": snap.bytes_sent,
"bytes_recv": snap.bytes_recv,
"send_errors": snap.send_errors,
"recv_errors": snap.recv_errors,
"beacons_sent": snap.beacons_sent,
"beacons_recv": snap.beacons_recv,
"frames_too_short": snap.frames_too_short,
"frames_too_long": snap.frames_too_long,
})
serde_json::to_value(t.stats().snapshot()).unwrap_or_default()
}
TransportHandle::Tcp(t) => {
serde_json::to_value(t.stats().snapshot()).unwrap_or_default()