Chore(Stage): Some Refactoring

This commit is contained in:
Tochukwu Nkemdilim
2018-07-18 17:23:31 +01:00
parent cb161ba6c2
commit 468368bc30
7 changed files with 60 additions and 166 deletions
+12 -25
View File
@@ -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),
}
}
}