Skip to content

Commit

Permalink
Fixed clippy warnings and reformat sources.
Browse files Browse the repository at this point in the history
  • Loading branch information
fpagliughi committed Oct 24, 2022
1 parent 1d1f69f commit eee12c6
Show file tree
Hide file tree
Showing 16 changed files with 51 additions and 54 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,9 @@ To keep up with the latest announcements for this project, follow:
- New URI protocol schemes: "mqtt://" for TCP and "mqtts://" for encrypted SSL/TLS.
- Updated `SubscribeOptions` to be more usable.
- Created a new [example](https://github.com/eclipse/paho.mqtt.rust/blob/develop/examples/async_subscribe_v5.rs) for MQTT v5 subscriptions with subscribe options.
[#156](https://github.com/eclipse/paho.mqtt.rust/issues/156) Added a mutable iterator to TopicMatcher, with functions `remove()`, `get_mut()`, and `matches_mut()`
[#170](https://github.com/eclipse/paho.mqtt.rust/issues/170) Upgraded cmake crate to v0.1.48 to support building with Visual Studio 2022.
- [#156](https://github.com/eclipse/paho.mqtt.rust/issues/156) Added a mutable iterator to TopicMatcher, with functions `remove()`, `get_mut()`, and `matches_mut()`
- [#170](https://github.com/eclipse/paho.mqtt.rust/issues/170) Upgraded cmake crate to v0.1.48 to support building with Visual Studio 2022.
- Fixed clippy warnings

### What's new in v0.11.1

Expand Down
3 changes: 2 additions & 1 deletion examples/async_subscribe_v5.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ fn main() {

println!("Subscribing to topics: {:?}", TOPICS);
let sub_opts = vec![mqtt::SubscribeOptions::with_retain_as_published(); TOPICS.len()];
cli.subscribe_many_with_options(TOPICS, QOS, &sub_opts, None).await?;
cli.subscribe_many_with_options(TOPICS, QOS, &sub_opts, None)
.await?;

// Just loop on incoming messages.
println!("Waiting for messages...");
Expand Down
12 changes: 6 additions & 6 deletions src/async_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ use crate::{
use crossbeam_channel as channel;
use std::{
ffi::{CStr, CString},
mem,
os::raw::{c_char, c_int, c_void},
ptr, slice, str,
sync::{Arc, Mutex},
Expand Down Expand Up @@ -834,8 +833,7 @@ impl AsyncClient {
self.inner.handle,
n as c_int,
topics.as_c_arr_mut_ptr(),
// C lib takes mutable QoS ptr, but doesn't mutate
mem::transmute(qos.as_ptr()),
qos.as_ptr(),
&mut rsp_opts.copts,
)
};
Expand Down Expand Up @@ -881,16 +879,18 @@ impl AsyncClient {

let topics = StringCollection::new(topics);

debug!("Subscribe to '{:?}' @ QOS {:?} w/ opts: {:?}", topics, qos, opts);
debug!(
"Subscribe to '{:?}' @ QOS {:?} w/ opts: {:?}",
topics, qos, opts
);
trace!("Subscribe call/response opts: {:?}", rsp_opts);

let rc = unsafe {
ffi::MQTTAsync_subscribeMany(
self.inner.handle,
n as c_int,
topics.as_c_arr_mut_ptr(),
// C lib takes mutable QoS ptr, but doesn't mutate
mem::transmute(qos.as_ptr()),
qos.as_ptr(),
&mut rsp_opts.copts,
)
};
Expand Down
2 changes: 1 addition & 1 deletion src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,9 +310,9 @@ impl Client {
#[cfg(test)]
mod tests {
use super::*;
use crate::create_options::CreateOptionsBuilder;
use std::sync::Arc;
use std::thread;
use crate::create_options::CreateOptionsBuilder;

// Determine that a client can be sent across threads and signaled.
// As long as it compiles, this indicates that Client implements the
Expand Down
2 changes: 1 addition & 1 deletion src/connect_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ impl Default for ConnectOptions {

impl Clone for ConnectOptions {
fn clone(&self) -> Self {
Self::from_data(self.copts, (&*self.data).clone())
Self::from_data(self.copts, (*self.data).clone())
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
//

/*******************************************************************************
* Copyright (c) 2017-2020 Frank Pagliughi <[email protected]>
* Copyright (c) 2017-2022 Frank Pagliughi <[email protected]>
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
Expand Down Expand Up @@ -187,7 +187,7 @@ impl Default for Message {
impl Clone for Message {
/// Create a clone of the message
fn clone(&self) -> Self {
Self::from_data(self.cmsg, (&*self.data).clone())
Self::from_data(self.cmsg, (*self.data).clone())
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/name_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ impl Default for NameValueCollection {

impl Clone for NameValueCollection {
fn clone(&self) -> Self {
Self::from_data((&*self.data).clone())
Self::from_data((*self.data).clone())
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/properties.rs
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ impl Property {
Self::new_binary(code, v.to_vec())
}
else if let Some(v) = rval.downcast_ref::<String>() {
Self::new_string(code, &*v)
Self::new_string(code, v)
}
else if let Some(v) = rval.downcast_ref::<&str>() {
Self::new_string(code, v)
Expand Down
4 changes: 2 additions & 2 deletions src/reason_code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
//

/*******************************************************************************
* Copyright (c) 2019-2020 Frank Pagliughi <[email protected]>
* Copyright (c) 2019-2022 Frank Pagliughi <[email protected]>
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
Expand All @@ -25,7 +25,7 @@ use std::{ffi::CStr, fmt};

/// MQTT v5 single-byte reason codes.
#[repr(u8)]
#[derive(Clone, Copy, PartialEq, Debug)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[allow(missing_docs)]
pub enum ReasonCode {
Success = 0, // also: NormalDisconnection & GrantedQos0
Expand Down
5 changes: 1 addition & 4 deletions src/response_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,10 +280,7 @@ mod tests {
assert!(!opts.copts.subscribeOptionsList.is_null());

unsafe {
let sub_opts_list = std::slice::from_raw_parts(
opts.copts.subscribeOptionsList,
4
);
let sub_opts_list = std::slice::from_raw_parts(opts.copts.subscribeOptionsList, 4);
assert!(sub_opts_list[0].noLocal != 0);
assert!(sub_opts_list[1].noLocal != 0);
assert!(sub_opts_list[2].noLocal != 0);
Expand Down
7 changes: 3 additions & 4 deletions src/server_response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
//

/*******************************************************************************
* Copyright (c) 2018-2020 Frank Pagliughi <[email protected]>
* Copyright (c) 2018-2022 Frank Pagliughi <[email protected]>
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
Expand All @@ -31,17 +31,16 @@
//! combined with any other Rust futures.
//!

use std::ffi::CStr;

use crate::{ffi, from_c_bool, properties::Properties, reason_code::ReasonCode};
use std::ffi::CStr;

/////////////////////////////////////////////////////////////////////////////
// ServerRequest

/// The server requests that expect a response.
/// This is required because the `alt` union of the MQTTAsync_successData
/// struct from C library doesn't indicate which field is valid.
#[derive(Clone, Copy, PartialEq, Debug)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ServerRequest {
/// No response expected from the server
None,
Expand Down
6 changes: 3 additions & 3 deletions src/ssl_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
//

/*******************************************************************************
* Copyright (c) 2017-2020 Frank Pagliughi <[email protected]>
* Copyright (c) 2017-2022 Frank Pagliughi <[email protected]>
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
Expand Down Expand Up @@ -69,7 +69,7 @@ struct SslOptionsData {

/// The SSL/TLS versions that can be requested.
#[repr(u32)]
#[derive(Clone, Copy, PartialEq, Debug)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum SslVersion {
/// The default library SSL/TLS version
Default = ffi::MQTT_SSL_VERSION_DEFAULT,
Expand Down Expand Up @@ -200,7 +200,7 @@ impl Default for SslOptions {

impl Clone for SslOptions {
fn clone(&self) -> Self {
Self::from_data(self.copts, (&*self.data).clone())
Self::from_data(self.copts, (*self.data).clone())
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/string_collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ impl Default for StringCollection {

impl Clone for StringCollection {
fn clone(&self) -> Self {
Self::from_data((&*self.data).clone())
Self::from_data((*self.data).clone())
}
}

Expand Down
12 changes: 2 additions & 10 deletions src/subscribe_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,12 @@
use crate::{ffi, from_c_bool, to_c_bool, Error, Result};
use std::{convert::TryFrom, fmt};


/// Receive our own publications when subscribed to the same topics.
/// This is the default and the same behavior as MQTT v3.x
pub const SUBSCRIBE_LOCAL: bool = false;
/// Don't receive our own publications when subscribed to the same topics.
pub const SUBSCRIBE_NO_LOCAL: bool = true;


/// Retain flag is only set on publications sent by a broker if in
/// response to a subscribe request.
/// This is the default and the same behavior as MQTT v3.x
Expand Down Expand Up @@ -96,11 +94,7 @@ pub struct SubscribeOptions {

impl SubscribeOptions {
/// Creates set of subscribe options.
pub fn new<H>(
no_local: bool,
retain_as_published: bool,
retain_handling: H,
) -> Self
pub fn new<H>(no_local: bool, retain_as_published: bool, retain_handling: H) -> Self
where
H: Into<Option<RetainHandling>>,
{
Expand Down Expand Up @@ -158,8 +152,7 @@ impl SubscribeOptions {

/// Get the value of the 'retain handling' option.
pub fn retain_handling(&self) -> RetainHandling {
RetainHandling::try_from(self.copts.retainHandling as i32)
.unwrap_or_default()
RetainHandling::try_from(self.copts.retainHandling as i32).unwrap_or_default()
}
}

Expand Down Expand Up @@ -298,7 +291,6 @@ mod tests {
assert!(opts.copts.retainHandling == RetainHandling::SendRetainedOnNew as u8);
}


#[test]
fn test_with() {
let opts = SubscribeOptions::with_no_local();
Expand Down
32 changes: 19 additions & 13 deletions src/topic_matcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,9 @@ impl<T> TopicMatcher<T> {
for sym in key.split('/') {
node = match sym {
"+" => node.plus_wild.get_or_insert(Box::new(Node::<T>::default())),
"#" => node.pound_wild.get_or_insert(Box::new(Node::<T>::default())),
"#" => node
.pound_wild
.get_or_insert(Box::new(Node::<T>::default())),
sym => node
.children
.entry(sym.to_string())
Expand All @@ -124,7 +126,7 @@ impl<T> TopicMatcher<T> {
None => return None,
};
}
node.content.take().map(|(_,v)| v)
node.content.take().map(|(_, v)| v)
}

/// Gets a reference to a value from the collection using an exact
Expand All @@ -142,7 +144,7 @@ impl<T> TopicMatcher<T> {
None => return None,
};
}
node.content.as_ref().map(|(_,v)| v)
node.content.as_ref().map(|(_, v)| v)
}

/// Gets a mutable mutable reference to a value from the collection
Expand All @@ -160,7 +162,7 @@ impl<T> TopicMatcher<T> {
None => return None,
};
}
node.content.as_mut().map(|(_,v)| v)
node.content.as_mut().map(|(_, v)| v)
}

/// Gets an iterator for all the matches to the specified topic
Expand Down Expand Up @@ -224,8 +226,10 @@ impl<T> Node<T> {
/// contain a collection of children that are empty, which might be
/// considered an "empty" state. But not here.
fn is_empty(&self) -> bool {
self.content.is_none() && self.children.is_empty()
&& self.plus_wild.is_none() && self.pound_wild.is_none()
self.content.is_none()
&& self.children.is_empty()
&& self.plus_wild.is_none()
&& self.pound_wild.is_none()
}
}

Expand Down Expand Up @@ -263,7 +267,9 @@ pub struct MatchIter<'a, 'b, T> {
impl<'a, 'b, T> MatchIter<'a, 'b, T> {
fn new(node: &'a Node<T>, topic: &'b str) -> Self {
let syms: Vec<_> = topic.rsplit('/').collect();
Self { nodes: vec![(node, syms)] }
Self {
nodes: vec![(node, syms)],
}
}
}

Expand Down Expand Up @@ -313,7 +319,9 @@ pub struct MatchIterMut<'a, 'b, T> {
impl<'a, 'b, T> MatchIterMut<'a, 'b, T> {
fn new(node: &'a mut Node<T>, topic: &'b str) -> Self {
let syms: Vec<_> = topic.rsplit('/').collect();
Self { nodes: vec![(node, syms)] }
Self {
nodes: vec![(node, syms)],
}
}
}

Expand All @@ -329,7 +337,7 @@ impl<'a, 'b, T> Iterator for MatchIterMut<'a, 'b, T> {

let sym = match syms.pop() {
Some(sym) => sym,
None => return node.content.as_mut().map(|(k,v)| (&*k, v)),
None => return node.content.as_mut().map(|(k, v)| (&*k, v)),
};

if let Some(child) = node.children.get_mut(sym) {
Expand All @@ -342,7 +350,7 @@ impl<'a, 'b, T> Iterator for MatchIterMut<'a, 'b, T> {

if let Some(child) = node.pound_wild.as_mut() {
// By protocol definition, a '#' must be a terminating leaf.
return child.content.as_mut().map(|(k,v)| (&*k, v));
return child.content.as_mut().map(|(k, v)| (&*k, v));
}

self.next()
Expand Down Expand Up @@ -392,9 +400,7 @@ mod tests {
fn test_topic_matcher_callback() {
let mut matcher = TopicMatcher::new();

matcher.insert("some/+/topic", Box::new(|n: u32| {
n * 2
}));
matcher.insert("some/+/topic", Box::new(|n: u32| n * 2));

for (_t, f) in matcher.matches("some/random/topic") {
let n = f(2);
Expand Down
5 changes: 3 additions & 2 deletions src/will_options.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
// will_options.rs
//
// This file is part of the Eclipse Paho MQTT Rust Client library.
//

/*******************************************************************************
* Copyright (c) 2017-2019 Frank Pagliughi <[email protected]>
* Copyright (c) 2017-2022 Frank Pagliughi <[email protected]>
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
Expand Down Expand Up @@ -172,7 +173,7 @@ impl Clone for WillOptions {
/// This clones the cached values and updates the C struct to refer
/// to them.
fn clone(&self) -> Self {
Self::from_data(self.copts, (&*self.data).clone())
Self::from_data(self.copts, (*self.data).clone())
}
}

Expand Down

0 comments on commit eee12c6

Please sign in to comment.