Struct NetworkManager

Source
pub struct NetworkManager { /* private fields */ }

Implementations§

Source§

impl NetworkManager

Source

pub fn new() -> Result<Self, Error>

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

pub fn new_with_dbus(dbus_connection: Connection) -> Self

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

Source

pub fn settings(&self) -> Result<Settings, Error>

Settings service object

Trait Implementations§

Source§

impl Clone for NetworkManager

Source§

fn clone(&self) -> NetworkManager

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for NetworkManager

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.