pub struct Device { /* private fields */ }
Implementations§
Source§impl Device
impl Device
Sourcepub fn device_type(&self) -> &DeviceType
pub fn device_type(&self) -> &DeviceType
Examples found in repository?
examples/create.rs (line 78)
73fn find_device(manager: &NetworkManager) -> Result<Device> {
74 let devices = manager.get_devices()?;
75
76 let index = devices
77 .iter()
78 .position(|d| *d.device_type() == DeviceType::WiFi);
79
80 if let Some(index) = index {
81 Ok(devices[index].clone())
82 } else {
83 bail!(ErrorKind::Runtime("Cannot find a WiFi device".into()))
84 }
85}
More examples
examples/hotspot.rs (line 115)
111fn find_device(manager: &NetworkManager, interface: Option<String>) -> Result<Device> {
112 if let Some(interface) = interface {
113 let device = manager.get_device_by_interface(&interface)?;
114
115 if *device.device_type() == DeviceType::WiFi {
116 Ok(device)
117 } else {
118 bail!(ErrorKind::Runtime(format!(
119 "{} is not a WiFi device",
120 interface
121 )))
122 }
123 } else {
124 let devices = manager.get_devices()?;
125
126 let index = devices
127 .iter()
128 .position(|d| *d.device_type() == DeviceType::WiFi);
129
130 if let Some(index) = index {
131 Ok(devices[index].clone())
132 } else {
133 bail!(ErrorKind::Runtime("Cannot find a WiFi device".into()))
134 }
135 }
136}
pub fn interface(&self) -> &str
pub fn get_state(&self) -> Result<DeviceState>
Sourcepub fn as_wifi_device(&self) -> Option<WiFiDevice<'_>>
pub fn as_wifi_device(&self) -> Option<WiFiDevice<'_>>
Examples found in repository?
examples/hotspot.rs (line 67)
52fn run() -> Result<()> {
53 let Options {
54 interface,
55 ssid,
56 password,
57 } = parse_options();
58
59 let pass_str = match password {
60 Some(ref s) => Some(s as &str),
61 None => None,
62 };
63
64 let manager = NetworkManager::new();
65
66 let device = find_device(&manager, interface)?;
67 let wifi_device = device.as_wifi_device().unwrap();
68
69 wifi_device.create_hotspot(&ssid as &str, pass_str, None)?;
70
71 Ok(())
72}
More examples
examples/create.rs (line 58)
46fn run() -> Result<()> {
47 let args: Vec<String> = env::args().collect();
48
49 if args.len() != 3 {
50 println!("USAGE: create SSID PASSWORD");
51 process::exit(1);
52 }
53
54 let manager = NetworkManager::new();
55
56 let device = find_device(&manager)?;
57
58 let wifi_device = device.as_wifi_device().unwrap();
59
60 let access_points = wifi_device.get_access_points()?;
61
62 let ap_index = find_access_point(&access_points, &args[1] as &str)?;
63
64 let credentials = AccessPointCredentials::Wpa {
65 passphrase: args[2].clone(),
66 };
67
68 wifi_device.connect(&access_points[ap_index], &credentials)?;
69
70 Ok(())
71}
Sourcepub fn connect(&self) -> Result<DeviceState>
pub fn connect(&self) -> Result<DeviceState>
Connects a Network Manager device.
Examples
use network_manager::{NetworkManager, DeviceType};
let manager = NetworkManager::new();
let devices = manager.get_devices().unwrap();
let i = devices.iter().position(|ref d| *d.device_type() == DeviceType::WiFi).unwrap();
devices[i].connect().unwrap();
Sourcepub fn disconnect(&self) -> Result<DeviceState>
pub fn disconnect(&self) -> Result<DeviceState>
Disconnect a Network Manager device.
§Examples
use network_manager::{NetworkManager, DeviceType};
let manager = NetworkManager::new();
let devices = manager.get_devices().unwrap();
let i = devices.iter().position(|ref d| *d.device_type() == DeviceType::WiFi).unwrap();
devices[i].disconnect().unwrap();
Trait Implementations§
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> 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