pub struct NetworkManager { /* private fields */ }Available on crate feature
network only.Implementations§
Source§impl NetworkManager
impl NetworkManager
Sourcepub fn connect() -> Result<Self, Error>
pub fn connect() -> Result<Self, Error>
Examples found in repository?
examples/network.rs (line 12)
11fn main() {
12 let dbus = NetworkManager::connect().unwrap();
13
14 for device in dbus.devices().unwrap() {
15 let state = device.state().unwrap();
16 let kind = device.kind().unwrap();
17 let interface = device.interface().unwrap();
18
19 println!("{:?} {:?} {:?}", interface, kind, state);
20 if let Ok(apn) = device.modem_apn() {
21 println!("- has apn {:?}", apn);
22 }
23
24 if matches!(state, DeviceState::Activated) {
25 let ipv4 = device.ipv4_config().unwrap().addresses().unwrap();
26 println!("- addresses {:?}", ipv4);
27 }
28 }
29
30 let dbus = ModemManager::connect().unwrap();
31
32 for modem in dbus.modems().unwrap() {
33 println!(
34 "modem {:?} {:?} {:?}",
35 modem.model().unwrap(),
36 modem.manufacturer().unwrap(),
37 modem.device().unwrap()
38 );
39
40 println!(
41 "- carrier configuration: {:?}",
42 modem.carrier_configuration().unwrap()
43 );
44
45 println!(
46 "- state: {:?}, signal: {:?}",
47 modem.state().unwrap(),
48 modem.signal_quality().unwrap()
49 );
50
51 let (allowed_modes, preffered_modes) = modem.current_modes().unwrap();
52 println!(
53 "- allowed modes: 2g: {} 3g: {} 4g: {} 5g: {}",
54 allowed_modes.has_2g(),
55 allowed_modes.has_3g(),
56 allowed_modes.has_4g(),
57 allowed_modes.has_5g()
58 );
59
60 println!(
61 "- prefered modes: 2g: {} 3g: {} 4g: {} 5g: {}",
62 preffered_modes.has_2g(),
63 preffered_modes.has_3g(),
64 preffered_modes.has_4g(),
65 preffered_modes.has_5g()
66 );
67
68 println!("- bands: {:?}", modem.current_bands().unwrap());
69
70 modem.signal_setup(10).unwrap();
71 thread::sleep(Duration::from_secs(1));
72
73 if let Ok(cdma) = modem.signal_cdma() {
74 println!("- cdma: {:?}", cdma);
75 }
76
77 if let Ok(evdo) = modem.signal_evdo() {
78 println!("- evdo: {:?}", evdo);
79 }
80
81 if let Ok(gsm) = modem.signal_gsm() {
82 println!("- gsm: {:?}", gsm);
83 }
84
85 if let Ok(umts) = modem.signal_umts() {
86 println!("- umts: {:?}", umts);
87 }
88
89 if let Ok(lte) = modem.signal_lte() {
90 println!("- lte: {:?}", lte);
91 }
92
93 if let Ok(nr5g) = modem.signal_nr5g() {
94 println!("- nr5g: {:?}", nr5g);
95 }
96 }
97}Sourcepub fn devices(&self) -> Result<Vec<Device>, Error>
pub fn devices(&self) -> Result<Vec<Device>, Error>
Examples found in repository?
examples/network.rs (line 14)
11fn main() {
12 let dbus = NetworkManager::connect().unwrap();
13
14 for device in dbus.devices().unwrap() {
15 let state = device.state().unwrap();
16 let kind = device.kind().unwrap();
17 let interface = device.interface().unwrap();
18
19 println!("{:?} {:?} {:?}", interface, kind, state);
20 if let Ok(apn) = device.modem_apn() {
21 println!("- has apn {:?}", apn);
22 }
23
24 if matches!(state, DeviceState::Activated) {
25 let ipv4 = device.ipv4_config().unwrap().addresses().unwrap();
26 println!("- addresses {:?}", ipv4);
27 }
28 }
29
30 let dbus = ModemManager::connect().unwrap();
31
32 for modem in dbus.modems().unwrap() {
33 println!(
34 "modem {:?} {:?} {:?}",
35 modem.model().unwrap(),
36 modem.manufacturer().unwrap(),
37 modem.device().unwrap()
38 );
39
40 println!(
41 "- carrier configuration: {:?}",
42 modem.carrier_configuration().unwrap()
43 );
44
45 println!(
46 "- state: {:?}, signal: {:?}",
47 modem.state().unwrap(),
48 modem.signal_quality().unwrap()
49 );
50
51 let (allowed_modes, preffered_modes) = modem.current_modes().unwrap();
52 println!(
53 "- allowed modes: 2g: {} 3g: {} 4g: {} 5g: {}",
54 allowed_modes.has_2g(),
55 allowed_modes.has_3g(),
56 allowed_modes.has_4g(),
57 allowed_modes.has_5g()
58 );
59
60 println!(
61 "- prefered modes: 2g: {} 3g: {} 4g: {} 5g: {}",
62 preffered_modes.has_2g(),
63 preffered_modes.has_3g(),
64 preffered_modes.has_4g(),
65 preffered_modes.has_5g()
66 );
67
68 println!("- bands: {:?}", modem.current_bands().unwrap());
69
70 modem.signal_setup(10).unwrap();
71 thread::sleep(Duration::from_secs(1));
72
73 if let Ok(cdma) = modem.signal_cdma() {
74 println!("- cdma: {:?}", cdma);
75 }
76
77 if let Ok(evdo) = modem.signal_evdo() {
78 println!("- evdo: {:?}", evdo);
79 }
80
81 if let Ok(gsm) = modem.signal_gsm() {
82 println!("- gsm: {:?}", gsm);
83 }
84
85 if let Ok(umts) = modem.signal_umts() {
86 println!("- umts: {:?}", umts);
87 }
88
89 if let Ok(lte) = modem.signal_lte() {
90 println!("- lte: {:?}", lte);
91 }
92
93 if let Ok(nr5g) = modem.signal_nr5g() {
94 println!("- nr5g: {:?}", nr5g);
95 }
96 }
97}Trait Implementations§
Source§impl Clone for NetworkManager
impl Clone for NetworkManager
Source§fn clone(&self) -> NetworkManager
fn clone(&self) -> NetworkManager
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl !RefUnwindSafe for NetworkManager
impl !Send for NetworkManager
impl !Sync for NetworkManager
impl !UnwindSafe for NetworkManager
impl Freeze for NetworkManager
impl Unpin for NetworkManager
impl UnsafeUnpin for NetworkManager
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more