[code] impl Iterator for LinkSpeed and use it
This commit is contained in:
parent
02640c5719
commit
ee24e38ba8
15
src/main.rs
15
src/main.rs
@ -68,18 +68,25 @@ impl LinkSpeed {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Iterator for LinkSpeed {
|
||||||
|
type Item = (f64, f64);
|
||||||
|
|
||||||
|
fn next(&mut self) -> Option<Self::Item> {
|
||||||
|
Some(self.get_measurement())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let netdev_name = env::args().nth(1).expect("No network device provided");
|
let netdev_name = env::args().nth(1).expect("No network device provided");
|
||||||
|
|
||||||
let mut link_speed = LinkSpeed::new(netdev_name).expect("Failed to create LinkSpeed object");
|
let link_speed = LinkSpeed::new(netdev_name).expect("Failed to create LinkSpeed object");
|
||||||
|
|
||||||
loop {
|
link_speed.for_each(|(rx_speed, tx_speed)| {
|
||||||
let (rx_speed, tx_speed) = link_speed.get_measurement();
|
|
||||||
println!(
|
println!(
|
||||||
"RX: {:.0} MBit/s, TX: {:.0} MBit/s",
|
"RX: {:.0} MBit/s, TX: {:.0} MBit/s",
|
||||||
rx_speed / 1024.0 / 1024.0 * 8.0,
|
rx_speed / 1024.0 / 1024.0 * 8.0,
|
||||||
tx_speed / 1024.0 / 1024.0 * 8.0
|
tx_speed / 1024.0 / 1024.0 * 8.0
|
||||||
);
|
);
|
||||||
sleep(Duration::from_millis(1000));
|
sleep(Duration::from_millis(1000));
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user