Compare commits

..

No commits in common. "716b91dd52ed2549d6618a01b52d08f808504bf2" and "b8694bb07aa7494ac0d7a47d9f5401c1c226b7fe" have entirely different histories.

3 changed files with 8 additions and 11 deletions

View File

@ -1,6 +1,8 @@
[package] [package]
name = "linkspeed" name = "linkspeed"
version = "0.1.0" version = "0.1.0"
edition = "2024"
rust-version = "1.85"
[dependencies] [dependencies]

2
rust-toolchain.toml Normal file
View File

@ -0,0 +1,2 @@
[toolchain]
channel = "nightly"

View File

@ -68,25 +68,18 @@ 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 link_speed = LinkSpeed::new(netdev_name).expect("Failed to create LinkSpeed object"); let mut link_speed = LinkSpeed::new(netdev_name).expect("Failed to create LinkSpeed object");
link_speed.for_each(|(rx_speed, tx_speed)| { loop {
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));
}); }
} }