use super::NetworkSnapshot;
#[derive(Clone, Copy, Default)]
pub(super) struct NetworkCounters {
pub(super) current: NetworkSnapshot,
pub(super) previous: NetworkSnapshot,
}
impl NetworkCounters {
#[cfg(not(target_os = "ios"))]
pub(super) fn new(current: NetworkSnapshot, previous: NetworkSnapshot) -> Self {
Self { current, previous }
}
#[cfg(not(target_os = "ios"))]
pub(super) fn update(&mut self, current: NetworkSnapshot) {
self.previous = self.current;
self.current = current;
}
pub(super) fn received(&self) -> u64 {
self.current.received.saturating_sub(self.previous.received)
}
pub(super) fn transmitted(&self) -> u64 {
self.current
.transmitted
.saturating_sub(self.previous.transmitted)
}
pub(super) fn packets_received(&self) -> u64 {
self.current
.packets_received
.saturating_sub(self.previous.packets_received)
}
pub(super) fn packets_transmitted(&self) -> u64 {
self.current
.packets_transmitted
.saturating_sub(self.previous.packets_transmitted)
}
pub(super) fn errors_received(&self) -> u64 {
self.current
.errors_received
.saturating_sub(self.previous.errors_received)
}
pub(super) fn errors_transmitted(&self) -> u64 {
self.current
.errors_transmitted
.saturating_sub(self.previous.errors_transmitted)
}
}