Skip to content

Commit a76d2a0

Browse files
authored
chore: fix clippy warnings (#947)
1 parent 49c3b5f commit a76d2a0

File tree

16 files changed

+40
-35
lines changed

16 files changed

+40
-35
lines changed

benchmarks/simplerouter/src/protocol/mod.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -282,12 +282,9 @@ pub fn length(stream: Iter<u8>) -> Result<(usize, usize), Error> {
282282

283283
/// Returns big endian u16 view from next 2 bytes
284284
pub fn view_u16(stream: &[u8]) -> Result<u16, Error> {
285-
let v = match stream.get(0..2) {
286-
Some(v) => (v[0] as u16) << 8 | (v[1] as u16),
287-
None => return Err(Error::MalformedPacket),
288-
};
285+
let v = stream.get(0..2).ok_or(Error::MalformedPacket)?;
289286

290-
Ok(v)
287+
Ok(((v[0] as u16) << 8) | (v[1] as u16))
291288
}
292289

293290
/// Returns big endian u16 view from next 2 bytes
@@ -306,7 +303,6 @@ pub fn view_str(stream: &[u8], end: usize) -> Result<&str, Error> {
306303
/// packet id or qos not being present. In cases where `read_mqtt_string` or
307304
/// `read_mqtt_bytes` exhausted remaining length but packet framing expects to
308305
/// parse qos next, these pre checks will prevent `bytes` crashes
309-
310306
fn read_u32(stream: &mut Bytes) -> Result<u32, Error> {
311307
if stream.len() < 4 {
312308
return Err(Error::MalformedPacket);

benchmarks/simplerouter/src/protocol/v4.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ pub(crate) mod connect {
183183
fn write(&self, buffer: &mut BytesMut) -> Result<u8, Error> {
184184
let mut connect_flags = 0;
185185

186-
connect_flags |= 0x04 | (self.qos as u8) << 3;
186+
connect_flags |= 0x04 | ((self.qos as u8) << 3);
187187
if self.retain {
188188
connect_flags |= 0x20;
189189
}
@@ -482,7 +482,7 @@ pub(crate) mod publish {
482482
let qos = qos as u8;
483483
let retain = retain as u8;
484484

485-
buffer.put_u8(0b0011_0000 | retain | qos << 1 | dup << 3);
485+
buffer.put_u8(0b0011_0000 | retain | (qos << 1) | (dup << 3));
486486

487487
let count = write_remaining_length(buffer, len)?;
488488
write_mqtt_string(buffer, topic);

benchmarks/simplerouter/src/protocol/v5.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1016,7 +1016,7 @@ pub(crate) mod publish {
10161016
let qos = qos as u8;
10171017
let retain = retain as u8;
10181018

1019-
buffer.put_u8(0b0011_0000 | retain | qos << 1 | dup << 3);
1019+
buffer.put_u8(0b0011_0000 | retain | (qos << 1) | (dup << 3));
10201020

10211021
let count = write_remaining_length(buffer, len)?;
10221022
write_mqtt_string(buffer, topic);
@@ -1314,10 +1314,10 @@ pub(crate) mod subscribe {
13141314
let options = read_u8(&mut bytes)?;
13151315
let requested_qos = options & 0b0000_0011;
13161316

1317-
let nolocal = options >> 2 & 0b0000_0001;
1317+
let nolocal = (options >> 2) & 0b0000_0001;
13181318
let nolocal = nolocal != 0;
13191319

1320-
let preserve_retain = options >> 3 & 0b0000_0001;
1320+
let preserve_retain = (options >> 3) & 0b0000_0001;
13211321
let preserve_retain = preserve_retain != 0;
13221322

13231323
let retain_forward_rule = (options >> 4) & 0b0000_0011;

rumqttc/src/mqttbytes/v4/connect.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ impl LastWill {
196196
fn write(&self, buffer: &mut BytesMut) -> Result<u8, Error> {
197197
let mut connect_flags = 0;
198198

199-
connect_flags |= 0x04 | (self.qos as u8) << 3;
199+
connect_flags |= 0x04 | ((self.qos as u8) << 3);
200200
if self.retain {
201201
connect_flags |= 0x20;
202202
}

rumqttc/src/mqttbytes/v4/publish.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ impl Publish {
8888
let dup = self.dup as u8;
8989
let qos = self.qos as u8;
9090
let retain = self.retain as u8;
91-
buffer.put_u8(0b0011_0000 | retain | qos << 1 | dup << 3);
91+
buffer.put_u8(0b0011_0000 | retain | (qos << 1) | (dup << 3));
9292

9393
let count = write_remaining_length(buffer, len)?;
9494
write_mqtt_string(buffer, self.topic.as_str());

rumqttc/src/v5/mqttbytes/v5/connect.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ impl LastWill {
427427
pub fn write(&self, buffer: &mut BytesMut) -> Result<u8, Error> {
428428
let mut connect_flags = 0;
429429

430-
connect_flags |= 0x04 | (self.qos as u8) << 3;
430+
connect_flags |= 0x04 | ((self.qos as u8) << 3);
431431
if self.retain {
432432
connect_flags |= 0x20;
433433
}

rumqttc/src/v5/mqttbytes/v5/publish.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ impl Publish {
9696
let dup = self.dup as u8;
9797
let qos = self.qos as u8;
9898
let retain = self.retain as u8;
99-
buffer.put_u8(0b0011_0000 | retain | qos << 1 | dup << 3);
99+
buffer.put_u8(0b0011_0000 | retain | (qos << 1) | (dup << 3));
100100

101101
let count = write_remaining_length(buffer, len)?;
102102
write_mqtt_bytes(buffer, &self.topic);

rumqttc/src/v5/mqttbytes/v5/subscribe.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,10 @@ impl Filter {
130130
let options = read_u8(bytes)?;
131131
let requested_qos = options & 0b0000_0011;
132132

133-
let nolocal = options >> 2 & 0b0000_0001;
133+
let nolocal = (options >> 2) & 0b0000_0001;
134134
let nolocal = nolocal != 0;
135135

136-
let preserve_retain = options >> 3 & 0b0000_0001;
136+
let preserve_retain = (options >> 3) & 0b0000_0001;
137137
let preserve_retain = preserve_retain != 0;
138138

139139
let retain_forward_rule = (options >> 4) & 0b0000_0011;

rumqttc/src/v5/state.rs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ impl MqttState {
242242
}
243243
_ => {
244244
warn!("SubAck Pkid = {:?}, Reason = {:?}", suback.pkid, reason);
245-
},
245+
}
246246
}
247247
}
248248
Ok(None)
@@ -364,7 +364,10 @@ impl MqttState {
364364
if puback.reason != PubAckReason::Success
365365
&& puback.reason != PubAckReason::NoMatchingSubscribers
366366
{
367-
warn!("PubAck Pkid = {:?}, reason: {:?}", puback.pkid, puback.reason);
367+
warn!(
368+
"PubAck Pkid = {:?}, reason: {:?}",
369+
puback.pkid, puback.reason
370+
);
368371
return Ok(None);
369372
}
370373

@@ -397,7 +400,10 @@ impl MqttState {
397400
if pubrec.reason != PubRecReason::Success
398401
&& pubrec.reason != PubRecReason::NoMatchingSubscribers
399402
{
400-
warn!("PubRec Pkid = {:?}, reason: {:?}", pubrec.pkid, pubrec.reason);
403+
warn!(
404+
"PubRec Pkid = {:?}, reason: {:?}",
405+
pubrec.pkid, pubrec.reason
406+
);
401407
return Ok(None);
402408
}
403409

@@ -417,7 +423,10 @@ impl MqttState {
417423
self.incoming_pub.set(pubrel.pkid as usize, false);
418424

419425
if pubrel.reason != PubRelReason::Success {
420-
warn!("PubRel Pkid = {:?}, reason: {:?}", pubrel.pkid, pubrel.reason);
426+
warn!(
427+
"PubRel Pkid = {:?}, reason: {:?}",
428+
pubrel.pkid, pubrel.reason
429+
);
421430
return Ok(None);
422431
}
423432

@@ -444,7 +453,10 @@ impl MqttState {
444453
self.outgoing_rel.set(pubcomp.pkid as usize, false);
445454

446455
if pubcomp.reason != PubCompReason::Success {
447-
warn!("PubComp Pkid = {:?}, reason: {:?}", pubcomp.pkid, pubcomp.reason);
456+
warn!(
457+
"PubComp Pkid = {:?}, reason: {:?}",
458+
pubcomp.pkid, pubcomp.reason
459+
);
448460
return Ok(None);
449461
}
450462

rumqttd/src/protocol/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ impl Publish {
210210
let dup = self.dup as u8;
211211
let qos = self.qos as u8;
212212
let retain = self.retain as u8;
213-
o.put_u8(0b0011_0000 | retain | qos << 1 | dup << 3);
213+
o.put_u8(0b0011_0000 | retain | (qos << 1) | (dup << 3));
214214
o.put_u16(self.pkid);
215215
o.put_u16(self.topic.len() as u16);
216216
o.extend_from_slice(&self.topic[..]);

0 commit comments

Comments
 (0)