wifi_rs/connectivity/
mod.rs

1#[cfg(target_os = "windows")]
2mod handlers;
3mod providers;
4#[cfg(target_os = "windows")]
5mod stubs;
6
7use crate::platforms::WifiError;
8use std::{fmt, io};
9
10/// Wireless network connectivity functionality.
11pub trait Connectivity: fmt::Debug {
12    /// Makes an attempt to connect to a selected wireless network with password specified.
13    fn connect(&mut self, ssid: &str, password: &str) -> Result<bool, WifiConnectionError>;
14
15    /// Disconnects from a wireless network currently connected to.
16    fn disconnect(&self) -> Result<bool, WifiConnectionError>;
17}
18
19/// Error that occurs when attempting to connect to a wireless network.
20#[derive(Debug)]
21pub enum WifiConnectionError {
22    /// Adding the newtork profile failed.
23    #[cfg(target_os = "windows")]
24    AddNetworkProfileFailed,
25    /// Failed to connect to wireless network.
26    FailedToConnect(String),
27    /// Failed to disconnect from wireless network. Try turning the wireless interface down.
28    FailedToDisconnect(String),
29    /// A wireless error occurred.
30    Other { kind: WifiError },
31    // SsidNotFound,
32}
33
34impl From<io::Error> for WifiConnectionError {
35    fn from(error: io::Error) -> Self {
36        WifiConnectionError::Other {
37            kind: WifiError::IoError(error),
38        }
39    }
40}