Struct NetworkManager

Source
pub struct NetworkManager<'a> { /* private fields */ }

Implementations§

Source§

impl<'a> NetworkManager<'a>

Source

pub fn new(dbus_connection: &'a Connection) -> Self

Examples found in repository?
examples/testing.rs (line 9)
6fn main() -> Result<(), Error> {
7    let dbus_connection = Connection::new_system()?;
8
9    let nm = NetworkManager::new(&dbus_connection);
10
11    for dev in nm.get_devices()? {
12        match dev {
13            Device::Ethernet(x) => {
14                println!("Is autoconnected: {:?}", x.autoconnect()?);
15                println!("Speed: {:?}", x.speed()?);
16                println!("S390 Subchannels: {:?}", x.s390_subchannels()?);
17                println!("Carrier: {:?}", x.carrier()?);
18                let conf = x.ip4_config()?;
19                println!("Gateway: {:?}", conf.gateway()?);
20                let con = x.active_connection()?;
21                println!("Connection id: {}", con.id()?);
22            }
23            Device::WiFi(x) => {
24                println!("Bitrate: {:?}", x.bitrate()?);
25                x.request_scan(std::collections::HashMap::new())?;
26                for ap in x.get_all_access_points()? {
27                    println!("SSID: {:?}", ap.ssid()?);
28                }
29            }
30            Device::Bluetooth(x) => {
31                println!("Name: {:?}", x.name()?);
32                println!("Capabilities: {}", Bluetooth::hw_address(&x)?);
33            }
34            _ => {}
35        }
36    }
37
38    let eth0 = nm.get_device_by_ip_iface("eth0")?;
39    match eth0 {
40        Device::Ethernet(x) => {
41            // NetworkManager >= 1.24
42            // println!("Hardware Address: {:?}", Any::hw_address(&x)?);
43
44            // NetworkManager < 1.24
45            // println!("Hardware Address: {:?}", Wired::hw_address(&x)?);
46
47            println!("Speed: {:?}", x.speed()?);
48        }
49        _ => {}
50    }
51
52    Ok(())
53}
Source

pub fn reload(&self, flags: ReloadFlag) -> Result<(), Error>

Reloads NetworkManager by the given scope

Source

pub fn get_devices(&self) -> Result<Vec<Device<'_>>, Error>

Returns only realized network devices

Examples found in repository?
examples/testing.rs (line 11)
6fn main() -> Result<(), Error> {
7    let dbus_connection = Connection::new_system()?;
8
9    let nm = NetworkManager::new(&dbus_connection);
10
11    for dev in nm.get_devices()? {
12        match dev {
13            Device::Ethernet(x) => {
14                println!("Is autoconnected: {:?}", x.autoconnect()?);
15                println!("Speed: {:?}", x.speed()?);
16                println!("S390 Subchannels: {:?}", x.s390_subchannels()?);
17                println!("Carrier: {:?}", x.carrier()?);
18                let conf = x.ip4_config()?;
19                println!("Gateway: {:?}", conf.gateway()?);
20                let con = x.active_connection()?;
21                println!("Connection id: {}", con.id()?);
22            }
23            Device::WiFi(x) => {
24                println!("Bitrate: {:?}", x.bitrate()?);
25                x.request_scan(std::collections::HashMap::new())?;
26                for ap in x.get_all_access_points()? {
27                    println!("SSID: {:?}", ap.ssid()?);
28                }
29            }
30            Device::Bluetooth(x) => {
31                println!("Name: {:?}", x.name()?);
32                println!("Capabilities: {}", Bluetooth::hw_address(&x)?);
33            }
34            _ => {}
35        }
36    }
37
38    let eth0 = nm.get_device_by_ip_iface("eth0")?;
39    match eth0 {
40        Device::Ethernet(x) => {
41            // NetworkManager >= 1.24
42            // println!("Hardware Address: {:?}", Any::hw_address(&x)?);
43
44            // NetworkManager < 1.24
45            // println!("Hardware Address: {:?}", Wired::hw_address(&x)?);
46
47            println!("Speed: {:?}", x.speed()?);
48        }
49        _ => {}
50    }
51
52    Ok(())
53}
Source

pub fn get_all_devices(&self) -> Result<Vec<Device<'_>>, Error>

Returns all the network devices

Source

pub fn get_device_by_ip_iface(&self, iface: &str) -> Result<Device<'_>, Error>

Examples found in repository?
examples/testing.rs (line 38)
6fn main() -> Result<(), Error> {
7    let dbus_connection = Connection::new_system()?;
8
9    let nm = NetworkManager::new(&dbus_connection);
10
11    for dev in nm.get_devices()? {
12        match dev {
13            Device::Ethernet(x) => {
14                println!("Is autoconnected: {:?}", x.autoconnect()?);
15                println!("Speed: {:?}", x.speed()?);
16                println!("S390 Subchannels: {:?}", x.s390_subchannels()?);
17                println!("Carrier: {:?}", x.carrier()?);
18                let conf = x.ip4_config()?;
19                println!("Gateway: {:?}", conf.gateway()?);
20                let con = x.active_connection()?;
21                println!("Connection id: {}", con.id()?);
22            }
23            Device::WiFi(x) => {
24                println!("Bitrate: {:?}", x.bitrate()?);
25                x.request_scan(std::collections::HashMap::new())?;
26                for ap in x.get_all_access_points()? {
27                    println!("SSID: {:?}", ap.ssid()?);
28                }
29            }
30            Device::Bluetooth(x) => {
31                println!("Name: {:?}", x.name()?);
32                println!("Capabilities: {}", Bluetooth::hw_address(&x)?);
33            }
34            _ => {}
35        }
36    }
37
38    let eth0 = nm.get_device_by_ip_iface("eth0")?;
39    match eth0 {
40        Device::Ethernet(x) => {
41            // NetworkManager >= 1.24
42            // println!("Hardware Address: {:?}", Any::hw_address(&x)?);
43
44            // NetworkManager < 1.24
45            // println!("Hardware Address: {:?}", Wired::hw_address(&x)?);
46
47            println!("Speed: {:?}", x.speed()?);
48        }
49        _ => {}
50    }
51
52    Ok(())
53}
Source

pub fn networking_enabled(&self) -> Result<bool, Error>

Source

pub fn wireless_enabled(&self) -> Result<bool, Error>

Source

pub fn wireless_hardware_enabled(&self) -> Result<bool, Error>

Source

pub fn startup(&self) -> Result<bool, Error>

Shows if NetworkManager is currently starting up

Auto Trait Implementations§

§

impl<'a> Freeze for NetworkManager<'a>

§

impl<'a> !RefUnwindSafe for NetworkManager<'a>

§

impl<'a> !Send for NetworkManager<'a>

§

impl<'a> !Sync for NetworkManager<'a>

§

impl<'a> Unpin for NetworkManager<'a>

§

impl<'a> !UnwindSafe for NetworkManager<'a>

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.