all functions established; needed to remove orphan functions
This commit is contained in:
@@ -5,10 +5,11 @@ use std::time::Instant;
|
||||
#[derive(Debug)]
|
||||
pub struct NetworkInfo {
|
||||
pub interfaces: Option<Vec<String>>,
|
||||
pub rx_bytes: Option<f64>,
|
||||
pub tx_bytes: Option<f64>,
|
||||
pub rx_rate: Option<f64>,
|
||||
pub tx_rate: Option<f64>,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct NetworkMonitor {
|
||||
prev_rx: u64,
|
||||
prev_tx: u64,
|
||||
@@ -24,7 +25,7 @@ impl NetworkMonitor {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_usage(&mut self) -> Result<(f64, f64), Box<dyn Error>> {
|
||||
pub fn update_usage(&mut self) -> Result<(f64, f64), Box<dyn Error>> {
|
||||
let (current_rx, current_tx) = get_network_bytes()?;
|
||||
let elapsed = self.last_update.elapsed().as_secs_f64();
|
||||
self.last_update = Instant::now();
|
||||
@@ -48,12 +49,12 @@ impl NetworkMonitor {
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn get_network_info() -> Result<NetworkInfo, Box<dyn Error>> {
|
||||
let (rx, tx) = get_network_bytes()?;
|
||||
pub async fn get_network_info(monitor: &mut NetworkMonitor) -> Result<NetworkInfo, Box<dyn Error>> {
|
||||
let (rx_rate, tx_rate) = monitor.update_usage()?;
|
||||
Ok(NetworkInfo {
|
||||
interfaces: Some(get_network_interfaces()),
|
||||
rx_bytes: Some(rx as f64),
|
||||
tx_bytes: Some(tx as f64),
|
||||
rx_rate: Some(rx_rate as f64),
|
||||
tx_rate: Some(tx_rate as f64),
|
||||
})
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user