diff --git a/README.md b/README.md index e0d42a3..1450cae 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/examples/async_subscribe_v5.rs b/examples/async_subscribe_v5.rs index 902c18c..513cd7f 100644 --- a/examples/async_subscribe_v5.rs +++ b/examples/async_subscribe_v5.rs @@ -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..."); diff --git a/src/async_client.rs b/src/async_client.rs index bbc1a22..8c00380 100644 --- a/src/async_client.rs +++ b/src/async_client.rs @@ -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}, @@ -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, ) }; @@ -881,7 +879,10 @@ 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 { @@ -889,8 +890,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, ) }; diff --git a/src/client.rs b/src/client.rs index 0bd0393..f5e2984 100644 --- a/src/client.rs +++ b/src/client.rs @@ -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 diff --git a/src/connect_options.rs b/src/connect_options.rs index cf70609..8541906 100644 --- a/src/connect_options.rs +++ b/src/connect_options.rs @@ -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()) } } diff --git a/src/message.rs b/src/message.rs index e704222..22f2ca4 100644 --- a/src/message.rs +++ b/src/message.rs @@ -4,7 +4,7 @@ // /******************************************************************************* - * Copyright (c) 2017-2020 Frank Pagliughi + * Copyright (c) 2017-2022 Frank Pagliughi * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -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()) } } diff --git a/src/name_value.rs b/src/name_value.rs index 9077c82..aae557f 100644 --- a/src/name_value.rs +++ b/src/name_value.rs @@ -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()) } } diff --git a/src/properties.rs b/src/properties.rs index 1239aff..ae0c795 100644 --- a/src/properties.rs +++ b/src/properties.rs @@ -379,7 +379,7 @@ impl Property { Self::new_binary(code, v.to_vec()) } else if let Some(v) = rval.downcast_ref::() { - Self::new_string(code, &*v) + Self::new_string(code, v) } else if let Some(v) = rval.downcast_ref::<&str>() { Self::new_string(code, v) diff --git a/src/reason_code.rs b/src/reason_code.rs index 604ee60..955fb04 100644 --- a/src/reason_code.rs +++ b/src/reason_code.rs @@ -4,7 +4,7 @@ // /******************************************************************************* - * Copyright (c) 2019-2020 Frank Pagliughi + * Copyright (c) 2019-2022 Frank Pagliughi * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -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 diff --git a/src/response_options.rs b/src/response_options.rs index 4482248..f5b00c2 100644 --- a/src/response_options.rs +++ b/src/response_options.rs @@ -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); diff --git a/src/server_response.rs b/src/server_response.rs index b904758..fa0e012 100644 --- a/src/server_response.rs +++ b/src/server_response.rs @@ -4,7 +4,7 @@ // /******************************************************************************* - * Copyright (c) 2018-2020 Frank Pagliughi + * Copyright (c) 2018-2022 Frank Pagliughi * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -31,9 +31,8 @@ //! 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 @@ -41,7 +40,7 @@ use crate::{ffi, from_c_bool, properties::Properties, reason_code::ReasonCode}; /// 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, diff --git a/src/ssl_options.rs b/src/ssl_options.rs index 1e1f283..bdb0e1c 100644 --- a/src/ssl_options.rs +++ b/src/ssl_options.rs @@ -4,7 +4,7 @@ // /******************************************************************************* - * Copyright (c) 2017-2020 Frank Pagliughi + * Copyright (c) 2017-2022 Frank Pagliughi * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -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, @@ -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()) } } diff --git a/src/string_collection.rs b/src/string_collection.rs index 57af3b9..632e292 100644 --- a/src/string_collection.rs +++ b/src/string_collection.rs @@ -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()) } } diff --git a/src/subscribe_options.rs b/src/subscribe_options.rs index 1fd7568..618954c 100644 --- a/src/subscribe_options.rs +++ b/src/subscribe_options.rs @@ -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 @@ -96,11 +94,7 @@ pub struct SubscribeOptions { impl SubscribeOptions { /// Creates set of subscribe options. - pub fn new( - no_local: bool, - retain_as_published: bool, - retain_handling: H, - ) -> Self + pub fn new(no_local: bool, retain_as_published: bool, retain_handling: H) -> Self where H: Into>, { @@ -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() } } @@ -298,7 +291,6 @@ mod tests { assert!(opts.copts.retainHandling == RetainHandling::SendRetainedOnNew as u8); } - #[test] fn test_with() { let opts = SubscribeOptions::with_no_local(); diff --git a/src/topic_matcher.rs b/src/topic_matcher.rs index c2f710e..65c5751 100644 --- a/src/topic_matcher.rs +++ b/src/topic_matcher.rs @@ -97,7 +97,9 @@ impl TopicMatcher { for sym in key.split('/') { node = match sym { "+" => node.plus_wild.get_or_insert(Box::new(Node::::default())), - "#" => node.pound_wild.get_or_insert(Box::new(Node::::default())), + "#" => node + .pound_wild + .get_or_insert(Box::new(Node::::default())), sym => node .children .entry(sym.to_string()) @@ -124,7 +126,7 @@ impl TopicMatcher { 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 @@ -142,7 +144,7 @@ impl TopicMatcher { 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 @@ -160,7 +162,7 @@ impl TopicMatcher { 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 @@ -224,8 +226,10 @@ impl Node { /// 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() } } @@ -263,7 +267,9 @@ pub struct MatchIter<'a, 'b, T> { impl<'a, 'b, T> MatchIter<'a, 'b, T> { fn new(node: &'a Node, topic: &'b str) -> Self { let syms: Vec<_> = topic.rsplit('/').collect(); - Self { nodes: vec![(node, syms)] } + Self { + nodes: vec![(node, syms)], + } } } @@ -313,7 +319,9 @@ pub struct MatchIterMut<'a, 'b, T> { impl<'a, 'b, T> MatchIterMut<'a, 'b, T> { fn new(node: &'a mut Node, topic: &'b str) -> Self { let syms: Vec<_> = topic.rsplit('/').collect(); - Self { nodes: vec![(node, syms)] } + Self { + nodes: vec![(node, syms)], + } } } @@ -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) { @@ -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() @@ -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); diff --git a/src/will_options.rs b/src/will_options.rs index 4864e3b..d71ddb5 100644 --- a/src/will_options.rs +++ b/src/will_options.rs @@ -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 + * Copyright (c) 2017-2022 Frank Pagliughi * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -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()) } }