NetworkData

Struct NetworkData 

Source
pub struct NetworkData { /* private fields */ }
Expand description

Getting volume of received and transmitted data.

use sysinfo::Networks;

let networks = Networks::new_with_refreshed_list();
for (interface_name, network) in &networks {
    println!("[{interface_name}] {network:?}");
}

Implementations§

Source§

impl NetworkData

Source

pub fn received(&self) -> u64

Returns the number of received bytes since the last refresh.

If you want the total number of bytes received, take a look at the total_received method.

use sysinfo::Networks;
use std::{thread, time};

let mut networks = Networks::new_with_refreshed_list();
// Waiting a bit to get data from network...
thread::sleep(time::Duration::from_millis(10));
// Refreshing again to generate diff.
networks.refresh(true);

for (interface_name, network) in &networks {
    println!("in: {} B", network.received());
}
Source

pub fn total_received(&self) -> u64

Returns the total number of received bytes.

If you want the amount of received bytes since the last refresh, take a look at the received method.

use sysinfo::Networks;

let networks = Networks::new_with_refreshed_list();
for (interface_name, network) in &networks {
    println!("in: {} B", network.total_received());
}
Source

pub fn transmitted(&self) -> u64

Returns the number of transmitted bytes since the last refresh.

If you want the total number of bytes transmitted, take a look at the total_transmitted method.

use sysinfo::Networks;
use std::{thread, time};

let mut networks = Networks::new_with_refreshed_list();
// Waiting a bit to get data from network...
thread::sleep(time::Duration::from_millis(10));
// Refreshing again to generate diff.
networks.refresh(true);

for (interface_name, network) in &networks {
    println!("out: {} B", network.transmitted());
}
Source

pub fn total_transmitted(&self) -> u64

Returns the total number of transmitted bytes.

If you want the amount of transmitted bytes since the last refresh, take a look at the transmitted method.

use sysinfo::Networks;

let networks = Networks::new_with_refreshed_list();
for (interface_name, network) in &networks {
    println!("out: {} B", network.total_transmitted());
}
Source

pub fn packets_received(&self) -> u64

Returns the number of incoming packets since the last refresh.

If you want the total number of packets received, take a look at the total_packets_received method.

use sysinfo::Networks;
use std::{thread, time};

let mut networks = Networks::new_with_refreshed_list();
// Waiting a bit to get data from network...
thread::sleep(time::Duration::from_millis(10));
// Refreshing again to generate diff.
networks.refresh(true);

for (interface_name, network) in &networks {
    println!("in: {}", network.packets_received());
}
Source

pub fn total_packets_received(&self) -> u64

Returns the total number of incoming packets.

If you want the amount of received packets since the last refresh, take a look at the packets_received method.

use sysinfo::Networks;

let networks = Networks::new_with_refreshed_list();
for (interface_name, network) in &networks {
    println!("in: {}", network.total_packets_received());
}
Source

pub fn packets_transmitted(&self) -> u64

Returns the number of outcoming packets since the last refresh.

If you want the total number of packets transmitted, take a look at the total_packets_transmitted method.

use sysinfo::Networks;
use std::{thread, time};

let mut networks = Networks::new_with_refreshed_list();
// Waiting a bit to get data from network...
thread::sleep(time::Duration::from_millis(10));
// Refreshing again to generate diff.
networks.refresh(true);

for (interface_name, network) in &networks {
    println!("out: {}", network.packets_transmitted());
}
Source

pub fn total_packets_transmitted(&self) -> u64

Returns the total number of outcoming packets.

If you want the amount of transmitted packets since the last refresh, take a look at the packets_transmitted method.

use sysinfo::Networks;

let networks = Networks::new_with_refreshed_list();
for (interface_name, network) in &networks {
    println!("out: {}", network.total_packets_transmitted());
}
Source

pub fn errors_on_received(&self) -> u64

Returns the number of incoming errors since the last refresh.

If you want the total number of errors on received packets, take a look at the total_errors_on_received method.

use sysinfo::Networks;
use std::{thread, time};

let mut networks = Networks::new_with_refreshed_list();
// Waiting a bit to get data from network...
thread::sleep(time::Duration::from_millis(10));
// Refreshing again to generate diff.
networks.refresh(true);

for (interface_name, network) in &networks {
    println!("in: {}", network.errors_on_received());
}
Source

pub fn total_errors_on_received(&self) -> u64

Returns the total number of incoming errors.

If you want the amount of errors on received packets since the last refresh, take a look at the errors_on_received method.

use sysinfo::Networks;

let networks = Networks::new_with_refreshed_list();
for (interface_name, network) in &networks {
    println!("in: {}", network.total_errors_on_received());
}
Source

pub fn errors_on_transmitted(&self) -> u64

Returns the number of outcoming errors since the last refresh.

If you want the total number of errors on transmitted packets, take a look at the total_errors_on_transmitted method.

use sysinfo::Networks;
use std::{thread, time};

let mut networks = Networks::new_with_refreshed_list();
// Waiting a bit to get data from network...
thread::sleep(time::Duration::from_millis(10));
// Refreshing again to generate diff.
networks.refresh(true);

for (interface_name, network) in &networks {
    println!("out: {}", network.errors_on_transmitted());
}
Source

pub fn total_errors_on_transmitted(&self) -> u64

Returns the total number of outcoming errors.

If you want the amount of errors on transmitted packets since the last refresh, take a look at the errors_on_transmitted method.

use sysinfo::Networks;

let networks = Networks::new_with_refreshed_list();
for (interface_name, network) in &networks {
    println!("out: {}", network.total_errors_on_transmitted());
}
Source

pub fn mac_address(&self) -> MacAddr

Returns the MAC address associated to current interface.

use sysinfo::Networks;

let mut networks = Networks::new_with_refreshed_list();
for (interface_name, network) in &networks {
    println!("MAC address: {}", network.mac_address());
}
Source

pub fn ip_networks(&self) -> &[IpNetwork]

Returns the Ip Networks associated to current interface.

use sysinfo::Networks;

let mut networks = Networks::new_with_refreshed_list();
for (interface_name, network) in &networks {
    println!("Ip Networks: {:?}", network.ip_networks());
}
Source

pub fn mtu(&self) -> u64

Returns the Maximum Transfer Unit (MTU) of the interface.

use sysinfo::Networks;

let mut networks = Networks::new_with_refreshed_list();
for (interface_name, network) in &networks {
    println!("mtu: {}", network.mtu());
}

Trait Implementations§

Source§

impl Debug for NetworkData

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.

Layout§

Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...) attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.

Size: 136 bytes