Struct Device

Source
pub struct Device { /* private fields */ }
Available on crate feature network only.

Implementations§

Source§

impl Device

Source

pub fn path(&self) -> Result<String, Error>

The path of the device as exposed by the udev property ID_PATH.
Note that non-UTF-8 characters are backslash escaped. Use g_strcompress() to obtain the true (non-UTF-8) string.

Source

pub fn interface(&self) -> Result<String, Error>

The name of the device’s control (and often data) interface. Note that non UTF-8 characters are backslash escaped, so the resulting name may be longer then 15 characters. Use g_strcompress() to revert the escaping.

Examples found in repository?
examples/network.rs (line 19)
12fn main() {
13
14	let dbus = NetworkManager::connect().unwrap();
15
16	for device in dbus.devices().unwrap() {
17		let state = device.state().unwrap();
18		let kind = device.kind().unwrap();
19		let interface = device.interface().unwrap();
20
21		println!("{:?} {:?} {:?}", interface, kind, state);
22		if let Ok(apn) = device.modem_apn() {
23			println!("- has apn {:?}", apn);
24		}
25
26		if matches!(state, DeviceState::Activated) {
27			let ipv4 = device.ipv4_config().unwrap()
28				.addresses().unwrap();
29			println!("- addresses {:?}", ipv4);
30		}
31	}
32
33	let dbus = ModemManager::connect().unwrap();
34
35	for modem in dbus.modems().unwrap() {
36		println!(
37			"modem {:?} {:?} {:?}",
38			modem.model().unwrap(),
39			modem.manufacturer().unwrap(),
40			modem.device().unwrap()
41		);
42
43		println!(
44			"- carrier configuration: {:?}",
45			modem.carrier_configuration().unwrap()
46		);
47
48		println!(
49			"- state: {:?}, signal: {:?}",
50			modem.state().unwrap(),
51			modem.signal_quality().unwrap()
52		);
53
54		let (allowed_modes, preffered_modes) = modem.current_modes().unwrap();
55		println!(
56			"- allowed modes: 2g: {} 3g: {} 4g: {} 5g: {}",
57			allowed_modes.has_2g(),
58			allowed_modes.has_3g(),
59			allowed_modes.has_4g(),
60			allowed_modes.has_5g()
61		);
62
63		println!(
64			"- prefered modes: 2g: {} 3g: {} 4g: {} 5g: {}",
65			preffered_modes.has_2g(),
66			preffered_modes.has_3g(),
67			preffered_modes.has_4g(),
68			preffered_modes.has_5g()
69		);
70
71		println!(
72			"- bands: {:?}",
73			modem.current_bands().unwrap()
74		);
75
76		modem.signal_setup(10).unwrap();
77		thread::sleep(Duration::from_secs(1));
78
79		if let Ok(cdma) = modem.signal_cdma() {
80			println!("- cdma: {:?}", cdma);
81		}
82
83		if let Ok(evdo) = modem.signal_evdo() {
84			println!("- evdo: {:?}", evdo);
85		}
86
87		if let Ok(gsm) = modem.signal_gsm() {
88			println!("- gsm: {:?}", gsm);
89		}
90
91		if let Ok(umts) = modem.signal_umts() {
92			println!("- umts: {:?}", umts);
93		}
94
95		if let Ok(lte) = modem.signal_lte() {
96			println!("- lte: {:?}", lte);
97		}
98
99		if let Ok(nr5g) = modem.signal_nr5g() {
100			println!("- nr5g: {:?}", nr5g);
101		}
102	}
103
104}
Source

pub fn driver(&self) -> Result<String, Error>

The driver handling the device. Non-UTF-8 sequences are backslash escaped. Use g_strcompress() to revert.

Source

pub fn state(&self) -> Result<DeviceState, Error>

The current state of the device.

Examples found in repository?
examples/network.rs (line 17)
12fn main() {
13
14	let dbus = NetworkManager::connect().unwrap();
15
16	for device in dbus.devices().unwrap() {
17		let state = device.state().unwrap();
18		let kind = device.kind().unwrap();
19		let interface = device.interface().unwrap();
20
21		println!("{:?} {:?} {:?}", interface, kind, state);
22		if let Ok(apn) = device.modem_apn() {
23			println!("- has apn {:?}", apn);
24		}
25
26		if matches!(state, DeviceState::Activated) {
27			let ipv4 = device.ipv4_config().unwrap()
28				.addresses().unwrap();
29			println!("- addresses {:?}", ipv4);
30		}
31	}
32
33	let dbus = ModemManager::connect().unwrap();
34
35	for modem in dbus.modems().unwrap() {
36		println!(
37			"modem {:?} {:?} {:?}",
38			modem.model().unwrap(),
39			modem.manufacturer().unwrap(),
40			modem.device().unwrap()
41		);
42
43		println!(
44			"- carrier configuration: {:?}",
45			modem.carrier_configuration().unwrap()
46		);
47
48		println!(
49			"- state: {:?}, signal: {:?}",
50			modem.state().unwrap(),
51			modem.signal_quality().unwrap()
52		);
53
54		let (allowed_modes, preffered_modes) = modem.current_modes().unwrap();
55		println!(
56			"- allowed modes: 2g: {} 3g: {} 4g: {} 5g: {}",
57			allowed_modes.has_2g(),
58			allowed_modes.has_3g(),
59			allowed_modes.has_4g(),
60			allowed_modes.has_5g()
61		);
62
63		println!(
64			"- prefered modes: 2g: {} 3g: {} 4g: {} 5g: {}",
65			preffered_modes.has_2g(),
66			preffered_modes.has_3g(),
67			preffered_modes.has_4g(),
68			preffered_modes.has_5g()
69		);
70
71		println!(
72			"- bands: {:?}",
73			modem.current_bands().unwrap()
74		);
75
76		modem.signal_setup(10).unwrap();
77		thread::sleep(Duration::from_secs(1));
78
79		if let Ok(cdma) = modem.signal_cdma() {
80			println!("- cdma: {:?}", cdma);
81		}
82
83		if let Ok(evdo) = modem.signal_evdo() {
84			println!("- evdo: {:?}", evdo);
85		}
86
87		if let Ok(gsm) = modem.signal_gsm() {
88			println!("- gsm: {:?}", gsm);
89		}
90
91		if let Ok(umts) = modem.signal_umts() {
92			println!("- umts: {:?}", umts);
93		}
94
95		if let Ok(lte) = modem.signal_lte() {
96			println!("- lte: {:?}", lte);
97		}
98
99		if let Ok(nr5g) = modem.signal_nr5g() {
100			println!("- nr5g: {:?}", nr5g);
101		}
102	}
103
104}
Source

pub fn kind(&self) -> Result<DeviceKind, Error>

The general type of the network device; ie Ethernet, Wi-Fi, etc.

Examples found in repository?
examples/network.rs (line 18)
12fn main() {
13
14	let dbus = NetworkManager::connect().unwrap();
15
16	for device in dbus.devices().unwrap() {
17		let state = device.state().unwrap();
18		let kind = device.kind().unwrap();
19		let interface = device.interface().unwrap();
20
21		println!("{:?} {:?} {:?}", interface, kind, state);
22		if let Ok(apn) = device.modem_apn() {
23			println!("- has apn {:?}", apn);
24		}
25
26		if matches!(state, DeviceState::Activated) {
27			let ipv4 = device.ipv4_config().unwrap()
28				.addresses().unwrap();
29			println!("- addresses {:?}", ipv4);
30		}
31	}
32
33	let dbus = ModemManager::connect().unwrap();
34
35	for modem in dbus.modems().unwrap() {
36		println!(
37			"modem {:?} {:?} {:?}",
38			modem.model().unwrap(),
39			modem.manufacturer().unwrap(),
40			modem.device().unwrap()
41		);
42
43		println!(
44			"- carrier configuration: {:?}",
45			modem.carrier_configuration().unwrap()
46		);
47
48		println!(
49			"- state: {:?}, signal: {:?}",
50			modem.state().unwrap(),
51			modem.signal_quality().unwrap()
52		);
53
54		let (allowed_modes, preffered_modes) = modem.current_modes().unwrap();
55		println!(
56			"- allowed modes: 2g: {} 3g: {} 4g: {} 5g: {}",
57			allowed_modes.has_2g(),
58			allowed_modes.has_3g(),
59			allowed_modes.has_4g(),
60			allowed_modes.has_5g()
61		);
62
63		println!(
64			"- prefered modes: 2g: {} 3g: {} 4g: {} 5g: {}",
65			preffered_modes.has_2g(),
66			preffered_modes.has_3g(),
67			preffered_modes.has_4g(),
68			preffered_modes.has_5g()
69		);
70
71		println!(
72			"- bands: {:?}",
73			modem.current_bands().unwrap()
74		);
75
76		modem.signal_setup(10).unwrap();
77		thread::sleep(Duration::from_secs(1));
78
79		if let Ok(cdma) = modem.signal_cdma() {
80			println!("- cdma: {:?}", cdma);
81		}
82
83		if let Ok(evdo) = modem.signal_evdo() {
84			println!("- evdo: {:?}", evdo);
85		}
86
87		if let Ok(gsm) = modem.signal_gsm() {
88			println!("- gsm: {:?}", gsm);
89		}
90
91		if let Ok(umts) = modem.signal_umts() {
92			println!("- umts: {:?}", umts);
93		}
94
95		if let Ok(lte) = modem.signal_lte() {
96			println!("- lte: {:?}", lte);
97		}
98
99		if let Ok(nr5g) = modem.signal_nr5g() {
100			println!("- nr5g: {:?}", nr5g);
101		}
102	}
103
104}
Source

pub fn ipv4_config(&self) -> Result<Ipv4Config, Error>

Ipv4 Configuration of the device. Only valid when the device is in DeviceState::Activated

Examples found in repository?
examples/network.rs (line 27)
12fn main() {
13
14	let dbus = NetworkManager::connect().unwrap();
15
16	for device in dbus.devices().unwrap() {
17		let state = device.state().unwrap();
18		let kind = device.kind().unwrap();
19		let interface = device.interface().unwrap();
20
21		println!("{:?} {:?} {:?}", interface, kind, state);
22		if let Ok(apn) = device.modem_apn() {
23			println!("- has apn {:?}", apn);
24		}
25
26		if matches!(state, DeviceState::Activated) {
27			let ipv4 = device.ipv4_config().unwrap()
28				.addresses().unwrap();
29			println!("- addresses {:?}", ipv4);
30		}
31	}
32
33	let dbus = ModemManager::connect().unwrap();
34
35	for modem in dbus.modems().unwrap() {
36		println!(
37			"modem {:?} {:?} {:?}",
38			modem.model().unwrap(),
39			modem.manufacturer().unwrap(),
40			modem.device().unwrap()
41		);
42
43		println!(
44			"- carrier configuration: {:?}",
45			modem.carrier_configuration().unwrap()
46		);
47
48		println!(
49			"- state: {:?}, signal: {:?}",
50			modem.state().unwrap(),
51			modem.signal_quality().unwrap()
52		);
53
54		let (allowed_modes, preffered_modes) = modem.current_modes().unwrap();
55		println!(
56			"- allowed modes: 2g: {} 3g: {} 4g: {} 5g: {}",
57			allowed_modes.has_2g(),
58			allowed_modes.has_3g(),
59			allowed_modes.has_4g(),
60			allowed_modes.has_5g()
61		);
62
63		println!(
64			"- prefered modes: 2g: {} 3g: {} 4g: {} 5g: {}",
65			preffered_modes.has_2g(),
66			preffered_modes.has_3g(),
67			preffered_modes.has_4g(),
68			preffered_modes.has_5g()
69		);
70
71		println!(
72			"- bands: {:?}",
73			modem.current_bands().unwrap()
74		);
75
76		modem.signal_setup(10).unwrap();
77		thread::sleep(Duration::from_secs(1));
78
79		if let Ok(cdma) = modem.signal_cdma() {
80			println!("- cdma: {:?}", cdma);
81		}
82
83		if let Ok(evdo) = modem.signal_evdo() {
84			println!("- evdo: {:?}", evdo);
85		}
86
87		if let Ok(gsm) = modem.signal_gsm() {
88			println!("- gsm: {:?}", gsm);
89		}
90
91		if let Ok(umts) = modem.signal_umts() {
92			println!("- umts: {:?}", umts);
93		}
94
95		if let Ok(lte) = modem.signal_lte() {
96			println!("- lte: {:?}", lte);
97		}
98
99		if let Ok(nr5g) = modem.signal_nr5g() {
100			println!("- nr5g: {:?}", nr5g);
101		}
102	}
103
104}
Source

pub fn modem_apn(&self) -> Result<String, Error>

The access point name the modem is connected to. Blank if disconnected.

Examples found in repository?
examples/network.rs (line 22)
12fn main() {
13
14	let dbus = NetworkManager::connect().unwrap();
15
16	for device in dbus.devices().unwrap() {
17		let state = device.state().unwrap();
18		let kind = device.kind().unwrap();
19		let interface = device.interface().unwrap();
20
21		println!("{:?} {:?} {:?}", interface, kind, state);
22		if let Ok(apn) = device.modem_apn() {
23			println!("- has apn {:?}", apn);
24		}
25
26		if matches!(state, DeviceState::Activated) {
27			let ipv4 = device.ipv4_config().unwrap()
28				.addresses().unwrap();
29			println!("- addresses {:?}", ipv4);
30		}
31	}
32
33	let dbus = ModemManager::connect().unwrap();
34
35	for modem in dbus.modems().unwrap() {
36		println!(
37			"modem {:?} {:?} {:?}",
38			modem.model().unwrap(),
39			modem.manufacturer().unwrap(),
40			modem.device().unwrap()
41		);
42
43		println!(
44			"- carrier configuration: {:?}",
45			modem.carrier_configuration().unwrap()
46		);
47
48		println!(
49			"- state: {:?}, signal: {:?}",
50			modem.state().unwrap(),
51			modem.signal_quality().unwrap()
52		);
53
54		let (allowed_modes, preffered_modes) = modem.current_modes().unwrap();
55		println!(
56			"- allowed modes: 2g: {} 3g: {} 4g: {} 5g: {}",
57			allowed_modes.has_2g(),
58			allowed_modes.has_3g(),
59			allowed_modes.has_4g(),
60			allowed_modes.has_5g()
61		);
62
63		println!(
64			"- prefered modes: 2g: {} 3g: {} 4g: {} 5g: {}",
65			preffered_modes.has_2g(),
66			preffered_modes.has_3g(),
67			preffered_modes.has_4g(),
68			preffered_modes.has_5g()
69		);
70
71		println!(
72			"- bands: {:?}",
73			modem.current_bands().unwrap()
74		);
75
76		modem.signal_setup(10).unwrap();
77		thread::sleep(Duration::from_secs(1));
78
79		if let Ok(cdma) = modem.signal_cdma() {
80			println!("- cdma: {:?}", cdma);
81		}
82
83		if let Ok(evdo) = modem.signal_evdo() {
84			println!("- evdo: {:?}", evdo);
85		}
86
87		if let Ok(gsm) = modem.signal_gsm() {
88			println!("- gsm: {:?}", gsm);
89		}
90
91		if let Ok(umts) = modem.signal_umts() {
92			println!("- umts: {:?}", umts);
93		}
94
95		if let Ok(lte) = modem.signal_lte() {
96			println!("- lte: {:?}", lte);
97		}
98
99		if let Ok(nr5g) = modem.signal_nr5g() {
100			println!("- nr5g: {:?}", nr5g);
101		}
102	}
103
104}

Auto Trait Implementations§

§

impl Freeze for Device

§

impl !RefUnwindSafe for Device

§

impl !Send for Device

§

impl !Sync for Device

§

impl Unpin for Device

§

impl !UnwindSafe for Device

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.