Struct NetworkManager

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

Implementations§

Source§

impl NetworkManager

Source

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

Examples found in repository?
examples/network.rs (line 14)
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 devices(&self) -> Result<Vec<Device>, Error>

Examples found in repository?
examples/network.rs (line 16)
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}

Trait Implementations§

Source§

impl Clone for NetworkManager

Source§

fn clone(&self) -> NetworkManager

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

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

Performs copy-assignment from source. 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.