Chore(Stage): Some Refactoring
This commit is contained in:
+12
-25
@@ -1,32 +1,23 @@
|
||||
pub mod profile_network;
|
||||
mod providers;
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
mod handlers;
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
mod stubs;
|
||||
|
||||
mod providers;
|
||||
|
||||
use platforms::WifiError;
|
||||
use std::{fmt, io};
|
||||
|
||||
pub trait Network: fmt::Debug {
|
||||
/// Makes an attempt to connect to a selected wireless network with password specified.
|
||||
fn connect(&self, password: &str) -> Result<bool, WifiConnectionError>;
|
||||
fn disconnect(&self) -> Result<bool, WifiConnectionError>;
|
||||
fn is_wifi_enabled(&self) -> bool;
|
||||
fn connnection_up(&self) -> bool;
|
||||
fn connnection_down(&self) -> bool;
|
||||
fn connect(&mut self, ssid: &str, password: &str) -> Result<bool, WifiConnectionError>;
|
||||
|
||||
// Hotspot
|
||||
// fn create_hotspot(&self, ssid: &str, password: &str) -> Result<bool, WifiHotspotError>;
|
||||
/// Disconnects from a wireless network currently connected to.
|
||||
fn disconnect(&self) -> Result<bool, WifiConnectionError>;
|
||||
}
|
||||
|
||||
// #[derive(Debug)]
|
||||
// pub enum NetworkType {
|
||||
// WEP,
|
||||
// WPA,
|
||||
// WPA2,
|
||||
// }
|
||||
|
||||
/// Configuration for a wifi network.
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Config<'a> {
|
||||
pub interface: Option<&'a str>,
|
||||
@@ -35,21 +26,17 @@ pub struct Config<'a> {
|
||||
#[derive(Debug)]
|
||||
pub enum WifiConnectionError {
|
||||
SsidNotFound,
|
||||
OsNotSupported,
|
||||
IpAssignFailed,
|
||||
AddNetworkProfileFailed,
|
||||
IoError(io::Error),
|
||||
FailedToConnect(String),
|
||||
FailedToDisconnect(String),
|
||||
WiFiInterfaceDisabled,
|
||||
}
|
||||
|
||||
pub enum WifiHotspotError {
|
||||
CreationFailed,
|
||||
Other { kind: WifiError },
|
||||
}
|
||||
|
||||
impl From<io::Error> for WifiConnectionError {
|
||||
fn from(error: io::Error) -> Self {
|
||||
WifiConnectionError::IoError(error)
|
||||
WifiConnectionError::Other {
|
||||
kind: WifiError::IoError(error),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user