use std::fmt;
use heim_common::prelude::*;
use heim_common::units::Information;
use crate::sys;
pub struct IoCounters(sys::IoCounters);
wrap!(IoCounters, sys::IoCounters);
impl IoCounters {
pub fn interface(&self) -> &str {
self.as_ref().interface()
}
pub fn bytes_sent(&self) -> Information {
self.as_ref().bytes_sent()
}
pub fn bytes_recv(&self) -> Information {
self.as_ref().bytes_recv()
}
pub fn packets_sent(&self) -> u64 {
self.as_ref().packets_sent()
}
pub fn packets_recv(&self) -> u64 {
self.as_ref().packets_recv()
}
pub fn errors_sent(&self) -> u64 {
self.as_ref().errors_sent()
}
pub fn errors_recv(&self) -> u64 {
self.as_ref().errors_recv()
}
pub fn drop_recv(&self) -> u64 {
self.as_ref().drop_recv()
}
}
impl fmt::Debug for IoCounters {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("IoCounters")
.field("interface", &self.interface())
.field("bytes_sent", &self.bytes_sent())
.field("bytes_recv", &self.bytes_recv())
.field("packets_sent", &self.packets_sent())
.field("packets_recv", &self.packets_recv())
.field("errors_sent", &self.errors_sent())
.field("errors_recv", &self.errors_recv())
.field("drop_recv", &self.drop_recv())
.finish()
}
}
pub fn io_counters() -> impl Stream<Item = Result<IoCounters>> {
sys::io_counters().map_ok(Into::into)
}