Skip to content

Commit 2bc1f1f

Browse files
authored
feat(rumqttc): remove unnecessary mut from v4 sync client methods (#646)
1 parent 0aa4ac3 commit 2bc1f1f

File tree

6 files changed

+15
-18
lines changed

6 files changed

+15
-18
lines changed

benchmarks/clients/rumqttsync.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ pub fn start(id: &str, payload_size: usize, count: usize) -> Result<(), Box<dyn
1717
mqttoptions.set_keep_alive(Duration::from_secs(20));
1818
mqttoptions.set_inflight(100);
1919

20-
let (mut client, mut connection) = Client::new(mqttoptions, 10);
20+
let (client, mut connection) = Client::new(mqttoptions, 10);
2121
thread::spawn(move || {
2222
for _i in 0..count {
2323
let payload = vec![0; payload_size];

rumqttc/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111
- Expose `EventLoop::clean` to allow triggering shutdown and subsequent storage of pending requests
1212

1313
### Changed
14+
- Synchronous client methods take `&self` instead of `&mut self` (#646)
1415

1516
### Deprecated
1617

rumqttc/examples/serde.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ impl TryFrom<&[u8]> for Message {
3434
fn main() {
3535
let mqqt_opts = MqttOptions::new("test-1", "localhost", 1883);
3636

37-
let (mut client, mut connection) = Client::new(mqqt_opts, 10);
37+
let (client, mut connection) = Client::new(mqqt_opts, 10);
3838
client.subscribe("hello/rumqtt", QoS::AtMostOnce).unwrap();
3939
thread::spawn(move || {
4040
for i in 0..10 {

rumqttc/examples/syncpubsub.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ fn main() {
2929
println!("Done with the stream!!");
3030
}
3131

32-
fn publish(mut client: Client) {
32+
fn publish(client: Client) {
3333
thread::sleep(Duration::from_secs(1));
3434
client.subscribe("hello/+/world", QoS::AtMostOnce).unwrap();
3535
for i in 0..10_usize {

rumqttc/examples/syncrecv.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ fn main() {
2727
}
2828
}
2929

30-
fn publish(mut client: Client) {
30+
fn publish(client: Client) {
3131
client.subscribe("hello/+/world", QoS::AtMostOnce).unwrap();
3232
for i in 0..3 {
3333
let payload = vec![1; i];

rumqttc/src/client.rs

+10-14
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ impl Client {
257257

258258
/// Sends a MQTT Publish to the `EventLoop`
259259
pub fn publish<S, V>(
260-
&mut self,
260+
&self,
261261
topic: S,
262262
qos: QoS,
263263
retain: bool,
@@ -279,7 +279,7 @@ impl Client {
279279
}
280280

281281
pub fn try_publish<S, V>(
282-
&mut self,
282+
&self,
283283
topic: S,
284284
qos: QoS,
285285
retain: bool,
@@ -310,25 +310,21 @@ impl Client {
310310
}
311311

312312
/// Sends a MQTT Subscribe to the `EventLoop`
313-
pub fn subscribe<S: Into<String>>(&mut self, topic: S, qos: QoS) -> Result<(), ClientError> {
313+
pub fn subscribe<S: Into<String>>(&self, topic: S, qos: QoS) -> Result<(), ClientError> {
314314
let subscribe = Subscribe::new(topic.into(), qos);
315315
let request = Request::Subscribe(subscribe);
316316
self.client.request_tx.send(request)?;
317317
Ok(())
318318
}
319319

320320
/// Sends a MQTT Subscribe to the `EventLoop`
321-
pub fn try_subscribe<S: Into<String>>(
322-
&mut self,
323-
topic: S,
324-
qos: QoS,
325-
) -> Result<(), ClientError> {
321+
pub fn try_subscribe<S: Into<String>>(&self, topic: S, qos: QoS) -> Result<(), ClientError> {
326322
self.client.try_subscribe(topic, qos)?;
327323
Ok(())
328324
}
329325

330326
/// Sends a MQTT Subscribe for multiple topics to the `EventLoop`
331-
pub fn subscribe_many<T>(&mut self, topics: T) -> Result<(), ClientError>
327+
pub fn subscribe_many<T>(&self, topics: T) -> Result<(), ClientError>
332328
where
333329
T: IntoIterator<Item = SubscribeFilter>,
334330
{
@@ -338,36 +334,36 @@ impl Client {
338334
Ok(())
339335
}
340336

341-
pub fn try_subscribe_many<T>(&mut self, topics: T) -> Result<(), ClientError>
337+
pub fn try_subscribe_many<T>(&self, topics: T) -> Result<(), ClientError>
342338
where
343339
T: IntoIterator<Item = SubscribeFilter>,
344340
{
345341
self.client.try_subscribe_many(topics)
346342
}
347343

348344
/// Sends a MQTT Unsubscribe to the `EventLoop`
349-
pub fn unsubscribe<S: Into<String>>(&mut self, topic: S) -> Result<(), ClientError> {
345+
pub fn unsubscribe<S: Into<String>>(&self, topic: S) -> Result<(), ClientError> {
350346
let unsubscribe = Unsubscribe::new(topic.into());
351347
let request = Request::Unsubscribe(unsubscribe);
352348
self.client.request_tx.send(request)?;
353349
Ok(())
354350
}
355351

356352
/// Sends a MQTT Unsubscribe to the `EventLoop`
357-
pub fn try_unsubscribe<S: Into<String>>(&mut self, topic: S) -> Result<(), ClientError> {
353+
pub fn try_unsubscribe<S: Into<String>>(&self, topic: S) -> Result<(), ClientError> {
358354
self.client.try_unsubscribe(topic)?;
359355
Ok(())
360356
}
361357

362358
/// Sends a MQTT disconnect to the `EventLoop`
363-
pub fn disconnect(&mut self) -> Result<(), ClientError> {
359+
pub fn disconnect(&self) -> Result<(), ClientError> {
364360
let request = Request::Disconnect(Disconnect);
365361
self.client.request_tx.send(request)?;
366362
Ok(())
367363
}
368364

369365
/// Sends a MQTT disconnect to the `EventLoop`
370-
pub fn try_disconnect(&mut self) -> Result<(), ClientError> {
366+
pub fn try_disconnect(&self) -> Result<(), ClientError> {
371367
self.client.try_disconnect()?;
372368
Ok(())
373369
}

0 commit comments

Comments
 (0)