Skip to content

Commit

Permalink
Auto-merge for PR #69 via VersionBot
Browse files Browse the repository at this point in the history
Clean up clippy warnings
  • Loading branch information
resin-io-modules-versionbot[bot] authored Jun 1, 2017
2 parents df801fe + 8cedba0 commit 083d347
Show file tree
Hide file tree
Showing 13 changed files with 170 additions and 157 deletions.
3 changes: 0 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ rust:
- nightly
- beta
- stable
matrix:
allow_failures:
- rust: nightly
before_install:
- sudo apt-get -qq update
- sudo apt-get install -yq --no-install-recommends libdbus-1-dev
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file
automatically by Versionist. DO NOT EDIT THIS FILE MANUALLY!
This project adheres to [Semantic Versioning](http://semver.org/).

## v0.2.4 - 2017-06-01

* Clean up clippy warnings [majorz]

## v0.2.3 - 2017-05-31

* Treat clippy warnings as errors [majorz]
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "network_manager"
version = "0.2.3"
version = "0.2.4"
authors = ["Joseph Roberts <[email protected]>", "Zahari Petkov <[email protected]>"]

[dependencies]
Expand Down
4 changes: 2 additions & 2 deletions examples/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ fn main() {
let devices = manager.get_devices().unwrap();
let device_index = devices
.iter()
.position(|ref d| *d.device_type() == DeviceType::WiFi)
.position(|d| *d.device_type() == DeviceType::WiFi)
.unwrap();
let wifi_device = devices[device_index].as_wifi_device().unwrap();

let access_points = wifi_device.get_access_points().unwrap();

let ap_index = access_points
.iter()
.position(|ref ap| ap.ssid().as_str().unwrap() == &args[1])
.position(|ap| ap.ssid().as_str().unwrap() == args[1])
.unwrap();

wifi_device
Expand Down
2 changes: 1 addition & 1 deletion examples/hotspot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ fn find_device(manager: &NetworkManager, interface: Option<String>) -> Option<De

let index = devices
.iter()
.position(|ref d| *d.device_type() == DeviceType::WiFi);
.position(|d| *d.device_type() == DeviceType::WiFi);

if let Some(index) = index {
Some(devices[index].clone())
Expand Down
21 changes: 12 additions & 9 deletions src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,13 @@ impl Connection {
match state {
ConnectionState::Activated => Ok(ConnectionState::Activated),
ConnectionState::Activating => {
wait(self, ConnectionState::Activated, self.dbus_manager.method_timeout())
wait(self, &ConnectionState::Activated, self.dbus_manager.method_timeout())
},
ConnectionState::Unknown => Err("Unable to get connection state".to_string()),
_ => {
self.dbus_manager.activate_connection(&self.path)?;

wait(self, ConnectionState::Activated, self.dbus_manager.method_timeout())
wait(self, &ConnectionState::Activated, self.dbus_manager.method_timeout())
},
}
}
Expand All @@ -93,7 +93,7 @@ impl Connection {
match state {
ConnectionState::Deactivated => Ok(ConnectionState::Deactivated),
ConnectionState::Deactivating => {
wait(self, ConnectionState::Deactivated, self.dbus_manager.method_timeout())
wait(self, &ConnectionState::Deactivated, self.dbus_manager.method_timeout())
},
ConnectionState::Unknown => Err("Unable to get connection state".to_string()),
_ => {
Expand All @@ -103,7 +103,7 @@ impl Connection {
if let Some(active_path) = active_path_option {
self.dbus_manager.deactivate_connection(&active_path)?;

wait(self, ConnectionState::Deactivated, self.dbus_manager.method_timeout())
wait(self, &ConnectionState::Deactivated, self.dbus_manager.method_timeout())
} else {
Ok(ConnectionState::Deactivated)
}
Expand Down Expand Up @@ -185,7 +185,10 @@ impl From<i64> for ConnectionState {
2 => ConnectionState::Activated,
3 => ConnectionState::Deactivating,
4 => ConnectionState::Deactivated,
_ => ConnectionState::Unknown,
_ => {
warn!("Undefined connection state: {}", state);
ConnectionState::Unknown
},
}
}
}
Expand Down Expand Up @@ -240,7 +243,7 @@ pub fn connect_to_access_point<P>(

let connection = Connection::init(dbus_manager, &path)?;

let state = wait(&connection, ConnectionState::Activated, dbus_manager.method_timeout())?;
let state = wait(&connection, &ConnectionState::Activated, dbus_manager.method_timeout())?;

Ok((connection, state))
}
Expand All @@ -260,7 +263,7 @@ pub fn create_hotspot<S, P>(

let connection = Connection::init(dbus_manager, &path)?;

let state = wait(&connection, ConnectionState::Activated, dbus_manager.method_timeout())?;
let state = wait(&connection, &ConnectionState::Activated, dbus_manager.method_timeout())?;

Ok((connection, state))
}
Expand All @@ -284,7 +287,7 @@ fn get_connection_active_path(

fn wait(
connection: &Connection,
target_state: ConnectionState,
target_state: &ConnectionState,
timeout: u64,
) -> Result<ConnectionState, String> {
if timeout == 0 {
Expand All @@ -302,7 +305,7 @@ fn wait(

total_time += 1;

if state == target_state {
if state == *target_state {
debug!("Connection target state reached: {:?} / {}s elapsed", state, total_time);

return Ok(state);
Expand Down
123 changes: 46 additions & 77 deletions src/dbus_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ impl DBusApi {
) -> Option<Result<Message, String>> {
match Message::new_method_call(self.base, path, interface, method) {
Ok(mut message) => {
if args.len() > 0 {
if !args.is_empty() {
message = message.append_ref(args);
}

Expand Down Expand Up @@ -155,7 +155,7 @@ impl DBusApi {

match path.get(interface, name) {
Ok(variant) => {
match DBusApi::variant_to(variant) {
match DBusApi::variant_to(&variant) {
Some(data) => Ok(data),
None => property_error("wrong property type"),
}
Expand All @@ -174,7 +174,7 @@ impl DBusApi {
{
response
.get1()
.ok_or("D-Bus wrong response type".to_string())
.ok_or_else(|| "D-Bus wrong response type".to_string())
}

pub fn extract_two<'a, T1, T2>(&self, response: &'a Message) -> Result<(T1, T2), String>
Expand All @@ -192,129 +192,98 @@ impl DBusApi {
Err("D-Bus wrong response type".to_string())
}

fn with_path<'a, P: Into<Path<'a>>>(&'a self, path: P) -> ConnPath<'a, &'a DBusConnection> {
fn with_path<'a, P: Into<Path<'a>>>(&'a self, path: P) -> ConnPath<&'a DBusConnection> {
self.connection
.with_path(self.base, path, self.method_timeout as i32 * 1000)
}
}


pub trait VariantTo<T> {
fn variant_to(value: Variant<Box<RefArg>>) -> Option<T>;
fn variant_to(value: &Variant<Box<RefArg>>) -> Option<T>;
}


impl VariantTo<String> for DBusApi {
fn variant_to(value: Variant<Box<RefArg>>) -> Option<String> {
variant_to_string(value)
fn variant_to(value: &Variant<Box<RefArg>>) -> Option<String> {
value.0.as_str().and_then(|v| Some(v.to_string()))
}
}


impl VariantTo<i64> for DBusApi {
fn variant_to(value: Variant<Box<RefArg>>) -> Option<i64> {
variant_to_i64(value)
fn variant_to(value: &Variant<Box<RefArg>>) -> Option<i64> {
value.0.as_i64()
}
}


impl VariantTo<u32> for DBusApi {
fn variant_to(value: Variant<Box<RefArg>>) -> Option<u32> {
variant_to_u32(value)
fn variant_to(value: &Variant<Box<RefArg>>) -> Option<u32> {
value.0.as_i64().and_then(|v| Some(v as u32))
}
}


impl VariantTo<bool> for DBusApi {
fn variant_to(value: Variant<Box<RefArg>>) -> Option<bool> {
variant_to_bool(value)
fn variant_to(value: &Variant<Box<RefArg>>) -> Option<bool> {
value.0.as_i64().and_then(|v| Some(v == 0))
}
}


impl VariantTo<Vec<String>> for DBusApi {
fn variant_to(value: Variant<Box<RefArg>>) -> Option<Vec<String>> {
variant_to_string_vec(value)
}
}


impl VariantTo<Vec<u8>> for DBusApi {
fn variant_to(value: Variant<Box<RefArg>>) -> Option<Vec<u8>> {
variant_to_u8_vec(value)
}
}


fn variant_to_string_vec(value: Variant<Box<RefArg>>) -> Option<Vec<String>> {
let mut result = Vec::new();

if let Some(list) = value.0.as_iter() {
for element in list {
if let Some(string) = element.as_str() {
result.push(string.to_string());
} else {
return None;
fn variant_to(value: &Variant<Box<RefArg>>) -> Option<Vec<String>> {
let mut result = Vec::new();

if let Some(list) = value.0.as_iter() {
for element in list {
if let Some(string) = element.as_str() {
result.push(string.to_string());
} else {
return None;
}
}
}

Some(result)
} else {
None
Some(result)
} else {
None
}
}
}


fn variant_to_u8_vec(value: Variant<Box<RefArg>>) -> Option<Vec<u8>> {
let mut result = Vec::new();

if let Some(list) = value.0.as_iter() {
for element in list {
if let Some(value) = element.as_i64() {
result.push(value as u8);
} else {
return None;
impl VariantTo<Vec<u8>> for DBusApi {
fn variant_to(value: &Variant<Box<RefArg>>) -> Option<Vec<u8>> {
let mut result = Vec::new();

if let Some(list) = value.0.as_iter() {
for element in list {
if let Some(value) = element.as_i64() {
result.push(value as u8);
} else {
return None;
}
}
}

Some(result)
} else {
None
Some(result)
} else {
None
}
}
}


fn variant_to_string(value: Variant<Box<RefArg>>) -> Option<String> {
value.0.as_str().and_then(|v| Some(v.to_string()))
}


fn variant_to_i64(value: Variant<Box<RefArg>>) -> Option<i64> {
value.0.as_i64()
}


fn variant_to_u32(value: Variant<Box<RefArg>>) -> Option<u32> {
value.0.as_i64().and_then(|v| Some(v as u32))
}


fn variant_to_bool(value: Variant<Box<RefArg>>) -> Option<bool> {
value.0.as_i64().and_then(|v| Some(v == 0))
}


pub fn extract<'a, T>(var: &'a Variant<Iter>) -> Result<T, String>
pub fn extract<'a, T>(var: &mut Variant<Iter<'a>>) -> Result<T, String>
where T: Get<'a>
{
var.0
.clone()
.get::<T>()
.ok_or(format!("D-Bus variant type does not match: {:?}", var))
.ok_or_else(|| format!("D-Bus variant type does not match: {:?}", var))
}

pub fn variant_iter_to_vec_u8(var: &Variant<Iter>) -> Result<Vec<u8>, String> {
let array_option = &var.0.clone().get::<Array<u8, _>>();
pub fn variant_iter_to_vec_u8(var: &mut Variant<Iter>) -> Result<Vec<u8>, String> {
let array_option = &var.0.get::<Array<u8, _>>();

if let Some(array) = *array_option {
Ok(array.collect())
Expand Down
Loading

0 comments on commit 083d347

Please sign in to comment.