Merge pull request #6 from TNkemdilim/hotfix/minor-cleanup
Chore(Cleanup): Resolve Warnings
This commit is contained in:
+38
-35
@@ -2,53 +2,56 @@ mod providers;
|
|||||||
|
|
||||||
use self::providers::prelude::HotspotConfig;
|
use self::providers::prelude::HotspotConfig;
|
||||||
use crate::platforms::{WifiError, WifiInterface};
|
use crate::platforms::{WifiError, WifiInterface};
|
||||||
use std::{fmt, io};
|
use std::fmt;
|
||||||
|
|
||||||
/// Error that might occur when interacting managing wireless hotspot.
|
/// Error that might occur when interacting managing wireless hotspot.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum WifiHotspotError {
|
pub enum WifiHotspotError {
|
||||||
/// Failed to ceate wireless hotspot.
|
/// Failed to ceate wireless hotspot.
|
||||||
CreationFailed,
|
#[cfg(target_os = "linux")]
|
||||||
/// Failed to stop wireless hotspot service. Try turning off
|
#[cfg(target_os = "windows")]
|
||||||
/// the wireless interface via ```wifi.turn_off()```.
|
CreationFailed,
|
||||||
FailedToStop(io::Error),
|
/// Failed to stop wireless hotspot service. Try turning off
|
||||||
/// A wireless interface error occurred.
|
/// the wireless interface via ```wifi.turn_off()```.
|
||||||
Other { kind: WifiError },
|
#[cfg(target_os = "linux")]
|
||||||
|
FailedToStop(std::io::Error),
|
||||||
|
/// A wireless interface error occurred.
|
||||||
|
Other { kind: WifiError },
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Wireless hotspot functionality for a wifi interface.
|
/// Wireless hotspot functionality for a wifi interface.
|
||||||
pub trait WifiHotspot: fmt::Debug + WifiInterface {
|
pub trait WifiHotspot: fmt::Debug + WifiInterface {
|
||||||
/// Creates wireless hotspot service for host machine. This only creates the wifi network,
|
/// Creates wireless hotspot service for host machine. This only creates the wifi network,
|
||||||
/// and isn't responsible for initiating the serving of the wifi network process.
|
/// and isn't responsible for initiating the serving of the wifi network process.
|
||||||
/// To begin serving the hotspot, use ```start_hotspot()```.
|
/// To begin serving the hotspot, use ```start_hotspot()```.
|
||||||
fn create_hotspot(
|
fn create_hotspot(
|
||||||
&mut self,
|
&mut self,
|
||||||
ssid: &str,
|
ssid: &str,
|
||||||
password: &str,
|
password: &str,
|
||||||
configuration: Option<&HotspotConfig>,
|
configuration: Option<&HotspotConfig>,
|
||||||
) -> Result<bool, WifiHotspotError> {
|
) -> Result<bool, WifiHotspotError> {
|
||||||
let _a = ssid;
|
let _a = ssid;
|
||||||
let _b = password;
|
let _b = password;
|
||||||
let _c = configuration;
|
let _c = configuration;
|
||||||
|
|
||||||
unimplemented!();
|
unimplemented!();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Start serving publicly an already created wireless hotspot.
|
/// Start serving publicly an already created wireless hotspot.
|
||||||
fn start_hotspot() -> Result<bool, WifiHotspotError> {
|
fn start_hotspot() -> Result<bool, WifiHotspotError> {
|
||||||
unimplemented!();
|
unimplemented!();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Stop serving a wireless network.
|
/// Stop serving a wireless network.
|
||||||
///
|
///
|
||||||
/// **NOTE: All users connected will automatically be disconnected.**
|
/// **NOTE: All users connected will automatically be disconnected.**
|
||||||
fn stop_hotspot(&mut self) -> Result<bool, WifiHotspotError> {
|
fn stop_hotspot(&mut self) -> Result<bool, WifiHotspotError> {
|
||||||
unimplemented!();
|
unimplemented!();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<WifiError> for WifiHotspotError {
|
impl From<WifiError> for WifiHotspotError {
|
||||||
fn from(error: WifiError) -> Self {
|
fn from(error: WifiError) -> Self {
|
||||||
WifiHotspotError::Other { kind: error }
|
WifiHotspotError::Other { kind: error }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,7 +26,6 @@ pub enum HotspotBand {
|
|||||||
Bg,
|
Bg,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(dead_code)]
|
|
||||||
#[derive(Debug, Clone, Copy)]
|
#[derive(Debug, Clone, Copy)]
|
||||||
/// Channel to broadcast wireless hotspot on.
|
/// Channel to broadcast wireless hotspot on.
|
||||||
pub enum Channel {
|
pub enum Channel {
|
||||||
|
|||||||
@@ -8,10 +8,10 @@ mod linux;
|
|||||||
mod osx;
|
mod osx;
|
||||||
|
|
||||||
pub mod prelude {
|
pub mod prelude {
|
||||||
#[cfg(target_os = "linux")]
|
#[cfg(target_os = "linux")]
|
||||||
pub use super::linux::*;
|
pub use super::linux::*;
|
||||||
#[cfg(target_os = "macos")]
|
#[cfg(target_os = "macos")]
|
||||||
pub use super::osx::*;
|
pub use super::osx::*;
|
||||||
#[cfg(target_os = "windows")]
|
#[cfg(target_os = "windows")]
|
||||||
pub use super::windows::*;
|
pub use super::windows::*;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,8 @@
|
|||||||
use hotspot::{WifiHotspot, WifiHotspotError};
|
use hotspot::WifiHotspot;
|
||||||
use connectivity::{Connectivity, WifiConnectionError};
|
|
||||||
use platforms::WiFi;
|
use platforms::WiFi;
|
||||||
use std::process::Command;
|
|
||||||
|
|
||||||
/// Configuration for a wireless hotspot.
|
/// Configuration for a wireless hotspot.
|
||||||
|
#[allow(dead_code)]
|
||||||
pub struct HotspotConfig {}
|
pub struct HotspotConfig {}
|
||||||
|
|
||||||
/// Wireless hotspot functionality for a wifi interface.
|
/// Wireless hotspot functionality for a wifi interface.
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ impl WifiInterface for Linux {
|
|||||||
|
|
||||||
/// Turn on the wireless network adapter.
|
/// Turn on the wireless network adapter.
|
||||||
fn turn_on() -> Result<(), WifiError> {
|
fn turn_on() -> Result<(), WifiError> {
|
||||||
let _output = Command::new("nmcli")
|
Command::new("nmcli")
|
||||||
.args(&["radio", "wifi", "on"])
|
.args(&["radio", "wifi", "on"])
|
||||||
.output()
|
.output()
|
||||||
.map_err(|err| WifiError::IoError(err))?;
|
.map_err(|err| WifiError::IoError(err))?;
|
||||||
@@ -52,7 +52,7 @@ impl WifiInterface for Linux {
|
|||||||
|
|
||||||
/// Turn off the wireless network adapter.
|
/// Turn off the wireless network adapter.
|
||||||
fn turn_off() -> Result<(), WifiError> {
|
fn turn_off() -> Result<(), WifiError> {
|
||||||
let _output = Command::new("nmcli")
|
Command::new("nmcli")
|
||||||
.args(&["radio", "wifi", "off"])
|
.args(&["radio", "wifi", "off"])
|
||||||
.output()
|
.output()
|
||||||
.map_err(|err| WifiError::IoError(err))?;
|
.map_err(|err| WifiError::IoError(err))?;
|
||||||
|
|||||||
+21
-21
@@ -17,36 +17,36 @@ use std::{fmt, io};
|
|||||||
/// Configuration for a wifi network.
|
/// Configuration for a wifi network.
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct Config<'a> {
|
pub struct Config<'a> {
|
||||||
/// The interface the wifi module is situated.
|
/// The interface the wifi module is situated.
|
||||||
pub interface: Option<&'a str>,
|
pub interface: Option<&'a str>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum WifiError {
|
pub enum WifiError {
|
||||||
// The specified wifi is currently disabled. Try switching it on.
|
// The specified wifi is currently disabled. Try switching it on.
|
||||||
WifiDisabled,
|
WifiDisabled,
|
||||||
/// The wifi interface interface failed to switch on.
|
/// The wifi interface interface failed to switch on.
|
||||||
#[cfg(target_os = "windows")]
|
#[cfg(target_os = "windows")]
|
||||||
InterfaceFailedToOn,
|
InterfaceFailedToOn,
|
||||||
/// IO Error occurred.
|
/// IO Error occurred.
|
||||||
IoError(io::Error),
|
IoError(io::Error),
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Wifi interface for an operating system.
|
/// Wifi interface for an operating system.
|
||||||
/// This provides basic functionalities for wifi interface.
|
/// This provides basic functionalities for wifi interface.
|
||||||
pub trait WifiInterface: fmt::Debug {
|
pub trait WifiInterface: fmt::Debug {
|
||||||
/// Check if the wifi interface on host machine is enabled.
|
/// Check if the wifi interface on host machine is enabled.
|
||||||
fn is_wifi_enabled() -> Result<bool, WifiError> {
|
fn is_wifi_enabled() -> Result<bool, WifiError> {
|
||||||
unimplemented!();
|
unimplemented!();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Turn on the wifi interface of host machine.
|
/// Turn on the wifi interface of host machine.
|
||||||
fn turn_on() -> Result<(), WifiError> {
|
fn turn_on() -> Result<(), WifiError> {
|
||||||
unimplemented!();
|
unimplemented!();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Turn off the wifi interface of host machine.
|
/// Turn off the wifi interface of host machine.
|
||||||
fn turn_off() -> Result<(), WifiError> {
|
fn turn_off() -> Result<(), WifiError> {
|
||||||
unimplemented!();
|
unimplemented!();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,15 +33,12 @@ impl WifiInterface for Osx {
|
|||||||
.output()
|
.output()
|
||||||
.map_err(|err| WifiError::IoError(err))?;
|
.map_err(|err| WifiError::IoError(err))?;
|
||||||
|
|
||||||
Ok(String::from_utf8_lossy(&output.stdout)
|
Ok(String::from_utf8_lossy(&output.stdout).contains("enabled"))
|
||||||
.replace(" ", "")
|
|
||||||
.replace("\n", "")
|
|
||||||
.contains("enabled"))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Turn on the wireless network adapter.
|
/// Turn on the wireless network adapter.
|
||||||
fn turn_on() -> Result<(), WifiError> {
|
fn turn_on() -> Result<(), WifiError> {
|
||||||
let output = Command::new("networksetup")
|
Command::new("networksetup")
|
||||||
.args(&["-setairportpower", "en0", "on"])
|
.args(&["-setairportpower", "en0", "on"])
|
||||||
.output()
|
.output()
|
||||||
.map_err(|err| WifiError::IoError(err))?;
|
.map_err(|err| WifiError::IoError(err))?;
|
||||||
@@ -51,7 +48,7 @@ impl WifiInterface for Osx {
|
|||||||
|
|
||||||
/// Turn off the wireless adapter.
|
/// Turn off the wireless adapter.
|
||||||
fn turn_off() -> Result<(), WifiError> {
|
fn turn_off() -> Result<(), WifiError> {
|
||||||
let output = Command::new("networksetup")
|
Command::new("networksetup")
|
||||||
.args(&["-setairportpower", "en0", "off"])
|
.args(&["-setairportpower", "en0", "off"])
|
||||||
.output()
|
.output()
|
||||||
.map_err(|err| WifiError::IoError(err))?;
|
.map_err(|err| WifiError::IoError(err))?;
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ impl WifiInterface for Windows {
|
|||||||
|
|
||||||
/// Turn on the wireless network adapter.
|
/// Turn on the wireless network adapter.
|
||||||
fn turn_on() -> Result<(), WifiError> {
|
fn turn_on() -> Result<(), WifiError> {
|
||||||
let _output = Command::new("netsh")
|
Command::new("netsh")
|
||||||
.args(&[
|
.args(&[
|
||||||
"interface",
|
"interface",
|
||||||
"set",
|
"set",
|
||||||
|
|||||||
Reference in New Issue
Block a user