From 22b6393d4da3f75f97e3270d78ba47c65a214c51 Mon Sep 17 00:00:00 2001 From: Tochukwu Nkemdilim Date: Sun, 29 Nov 2020 17:28:56 +0100 Subject: [PATCH] Chore(Cleanup): Resolve Warnings --- src/hotspot/mod.rs | 73 ++++++++++++++++++---------------- src/hotspot/providers/linux.rs | 1 - src/hotspot/providers/mod.rs | 12 +++--- src/hotspot/providers/osx.rs | 5 +-- src/platforms/linux.rs | 4 +- src/platforms/mod.rs | 42 +++++++++---------- src/platforms/osx.rs | 9 ++--- src/platforms/windows.rs | 2 +- 8 files changed, 73 insertions(+), 75 deletions(-) diff --git a/src/hotspot/mod.rs b/src/hotspot/mod.rs index f42e4be..4fdb61e 100644 --- a/src/hotspot/mod.rs +++ b/src/hotspot/mod.rs @@ -2,53 +2,56 @@ mod providers; use self::providers::prelude::HotspotConfig; use crate::platforms::{WifiError, WifiInterface}; -use std::{fmt, io}; +use std::fmt; /// Error that might occur when interacting managing wireless hotspot. #[derive(Debug)] pub enum WifiHotspotError { - /// Failed to ceate wireless hotspot. - CreationFailed, - /// Failed to stop wireless hotspot service. Try turning off - /// the wireless interface via ```wifi.turn_off()```. - FailedToStop(io::Error), - /// A wireless interface error occurred. - Other { kind: WifiError }, + /// Failed to ceate wireless hotspot. + #[cfg(target_os = "linux")] + #[cfg(target_os = "windows")] + CreationFailed, + /// Failed to stop wireless hotspot service. Try turning off + /// the wireless interface via ```wifi.turn_off()```. + #[cfg(target_os = "linux")] + FailedToStop(std::io::Error), + /// A wireless interface error occurred. + Other { kind: WifiError }, } /// Wireless hotspot functionality for a wifi interface. pub trait WifiHotspot: fmt::Debug + WifiInterface { - /// 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. - /// To begin serving the hotspot, use ```start_hotspot()```. - fn create_hotspot( - &mut self, - ssid: &str, - password: &str, - configuration: Option<&HotspotConfig>, - ) -> Result { - let _a = ssid; - let _b = password; - let _c = configuration; + /// 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. + /// To begin serving the hotspot, use ```start_hotspot()```. + fn create_hotspot( + &mut self, + ssid: &str, + password: &str, + configuration: Option<&HotspotConfig>, + ) -> Result { + let _a = ssid; + let _b = password; + let _c = configuration; - unimplemented!(); - } + unimplemented!(); + } - /// Start serving publicly an already created wireless hotspot. - fn start_hotspot() -> Result { - unimplemented!(); - } + /// Start serving publicly an already created wireless hotspot. + fn start_hotspot() -> Result { + unimplemented!(); + } - /// Stop serving a wireless network. - /// - /// **NOTE: All users connected will automatically be disconnected.** - fn stop_hotspot(&mut self) -> Result { - unimplemented!(); - } + /// Stop serving a wireless network. + /// + /// **NOTE: All users connected will automatically be disconnected.** + fn stop_hotspot(&mut self) -> Result { + unimplemented!(); + } } impl From for WifiHotspotError { - fn from(error: WifiError) -> Self { - WifiHotspotError::Other { kind: error } - } + fn from(error: WifiError) -> Self { + WifiHotspotError::Other { kind: error } + } } diff --git a/src/hotspot/providers/linux.rs b/src/hotspot/providers/linux.rs index 123b973..584f053 100644 --- a/src/hotspot/providers/linux.rs +++ b/src/hotspot/providers/linux.rs @@ -26,7 +26,6 @@ pub enum HotspotBand { Bg, } -#[allow(dead_code)] #[derive(Debug, Clone, Copy)] /// Channel to broadcast wireless hotspot on. pub enum Channel { diff --git a/src/hotspot/providers/mod.rs b/src/hotspot/providers/mod.rs index 0a3cc29..e907c44 100644 --- a/src/hotspot/providers/mod.rs +++ b/src/hotspot/providers/mod.rs @@ -8,10 +8,10 @@ mod linux; mod osx; pub mod prelude { - #[cfg(target_os = "linux")] - pub use super::linux::*; - #[cfg(target_os = "macos")] - pub use super::osx::*; - #[cfg(target_os = "windows")] - pub use super::windows::*; + #[cfg(target_os = "linux")] + pub use super::linux::*; + #[cfg(target_os = "macos")] + pub use super::osx::*; + #[cfg(target_os = "windows")] + pub use super::windows::*; } diff --git a/src/hotspot/providers/osx.rs b/src/hotspot/providers/osx.rs index 80affe9..1a4a92a 100644 --- a/src/hotspot/providers/osx.rs +++ b/src/hotspot/providers/osx.rs @@ -1,9 +1,8 @@ -use hotspot::{WifiHotspot, WifiHotspotError}; -use connectivity::{Connectivity, WifiConnectionError}; +use hotspot::WifiHotspot; use platforms::WiFi; -use std::process::Command; /// Configuration for a wireless hotspot. +#[allow(dead_code)] pub struct HotspotConfig {} /// Wireless hotspot functionality for a wifi interface. diff --git a/src/platforms/linux.rs b/src/platforms/linux.rs index 08ff498..fbc049a 100644 --- a/src/platforms/linux.rs +++ b/src/platforms/linux.rs @@ -42,7 +42,7 @@ impl WifiInterface for Linux { /// Turn on the wireless network adapter. fn turn_on() -> Result<(), WifiError> { - let _output = Command::new("nmcli") + Command::new("nmcli") .args(&["radio", "wifi", "on"]) .output() .map_err(|err| WifiError::IoError(err))?; @@ -52,7 +52,7 @@ impl WifiInterface for Linux { /// Turn off the wireless network adapter. fn turn_off() -> Result<(), WifiError> { - let _output = Command::new("nmcli") + Command::new("nmcli") .args(&["radio", "wifi", "off"]) .output() .map_err(|err| WifiError::IoError(err))?; diff --git a/src/platforms/mod.rs b/src/platforms/mod.rs index 5567607..29505fd 100644 --- a/src/platforms/mod.rs +++ b/src/platforms/mod.rs @@ -17,36 +17,36 @@ use std::{fmt, io}; /// Configuration for a wifi network. #[derive(Debug, Clone)] pub struct Config<'a> { - /// The interface the wifi module is situated. - pub interface: Option<&'a str>, + /// The interface the wifi module is situated. + pub interface: Option<&'a str>, } #[derive(Debug)] pub enum WifiError { - // The specified wifi is currently disabled. Try switching it on. - WifiDisabled, - /// The wifi interface interface failed to switch on. - #[cfg(target_os = "windows")] - InterfaceFailedToOn, - /// IO Error occurred. - IoError(io::Error), + // The specified wifi is currently disabled. Try switching it on. + WifiDisabled, + /// The wifi interface interface failed to switch on. + #[cfg(target_os = "windows")] + InterfaceFailedToOn, + /// IO Error occurred. + IoError(io::Error), } /// Wifi interface for an operating system. /// This provides basic functionalities for wifi interface. pub trait WifiInterface: fmt::Debug { - /// Check if the wifi interface on host machine is enabled. - fn is_wifi_enabled() -> Result { - unimplemented!(); - } + /// Check if the wifi interface on host machine is enabled. + fn is_wifi_enabled() -> Result { + unimplemented!(); + } - /// Turn on the wifi interface of host machine. - fn turn_on() -> Result<(), WifiError> { - unimplemented!(); - } + /// Turn on the wifi interface of host machine. + fn turn_on() -> Result<(), WifiError> { + unimplemented!(); + } - /// Turn off the wifi interface of host machine. - fn turn_off() -> Result<(), WifiError> { - unimplemented!(); - } + /// Turn off the wifi interface of host machine. + fn turn_off() -> Result<(), WifiError> { + unimplemented!(); + } } diff --git a/src/platforms/osx.rs b/src/platforms/osx.rs index 7b92ae0..c3207b5 100644 --- a/src/platforms/osx.rs +++ b/src/platforms/osx.rs @@ -33,15 +33,12 @@ impl WifiInterface for Osx { .output() .map_err(|err| WifiError::IoError(err))?; - Ok(String::from_utf8_lossy(&output.stdout) - .replace(" ", "") - .replace("\n", "") - .contains("enabled")) + Ok(String::from_utf8_lossy(&output.stdout).contains("enabled")) } /// Turn on the wireless network adapter. fn turn_on() -> Result<(), WifiError> { - let output = Command::new("networksetup") + Command::new("networksetup") .args(&["-setairportpower", "en0", "on"]) .output() .map_err(|err| WifiError::IoError(err))?; @@ -51,7 +48,7 @@ impl WifiInterface for Osx { /// Turn off the wireless adapter. fn turn_off() -> Result<(), WifiError> { - let output = Command::new("networksetup") + Command::new("networksetup") .args(&["-setairportpower", "en0", "off"]) .output() .map_err(|err| WifiError::IoError(err))?; diff --git a/src/platforms/windows.rs b/src/platforms/windows.rs index 4e05273..1252ab4 100644 --- a/src/platforms/windows.rs +++ b/src/platforms/windows.rs @@ -48,7 +48,7 @@ impl WifiInterface for Windows { /// Turn on the wireless network adapter. fn turn_on() -> Result<(), WifiError> { - let _output = Command::new("netsh") + Command::new("netsh") .args(&[ "interface", "set",