Skip to content

Commit

Permalink
chore: fix clippy warnings (#947)
Browse files Browse the repository at this point in the history
  • Loading branch information
de-sh authored Feb 27, 2025
1 parent 49c3b5f commit a76d2a0
Show file tree
Hide file tree
Showing 16 changed files with 40 additions and 35 deletions.
8 changes: 2 additions & 6 deletions benchmarks/simplerouter/src/protocol/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,12 +282,9 @@ pub fn length(stream: Iter<u8>) -> Result<(usize, usize), Error> {

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

Ok(v)
Ok(((v[0] as u16) << 8) | (v[1] as u16))
}

/// Returns big endian u16 view from next 2 bytes
Expand All @@ -306,7 +303,6 @@ pub fn view_str(stream: &[u8], end: usize) -> Result<&str, Error> {
/// packet id or qos not being present. In cases where `read_mqtt_string` or
/// `read_mqtt_bytes` exhausted remaining length but packet framing expects to
/// parse qos next, these pre checks will prevent `bytes` crashes
fn read_u32(stream: &mut Bytes) -> Result<u32, Error> {
if stream.len() < 4 {
return Err(Error::MalformedPacket);
Expand Down
4 changes: 2 additions & 2 deletions benchmarks/simplerouter/src/protocol/v4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ pub(crate) mod connect {
fn write(&self, buffer: &mut BytesMut) -> Result<u8, Error> {
let mut connect_flags = 0;

connect_flags |= 0x04 | (self.qos as u8) << 3;
connect_flags |= 0x04 | ((self.qos as u8) << 3);
if self.retain {
connect_flags |= 0x20;
}
Expand Down Expand Up @@ -482,7 +482,7 @@ pub(crate) mod publish {
let qos = qos as u8;
let retain = retain as u8;

buffer.put_u8(0b0011_0000 | retain | qos << 1 | dup << 3);
buffer.put_u8(0b0011_0000 | retain | (qos << 1) | (dup << 3));

let count = write_remaining_length(buffer, len)?;
write_mqtt_string(buffer, topic);
Expand Down
6 changes: 3 additions & 3 deletions benchmarks/simplerouter/src/protocol/v5.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1016,7 +1016,7 @@ pub(crate) mod publish {
let qos = qos as u8;
let retain = retain as u8;

buffer.put_u8(0b0011_0000 | retain | qos << 1 | dup << 3);
buffer.put_u8(0b0011_0000 | retain | (qos << 1) | (dup << 3));

let count = write_remaining_length(buffer, len)?;
write_mqtt_string(buffer, topic);
Expand Down Expand Up @@ -1314,10 +1314,10 @@ pub(crate) mod subscribe {
let options = read_u8(&mut bytes)?;
let requested_qos = options & 0b0000_0011;

let nolocal = options >> 2 & 0b0000_0001;
let nolocal = (options >> 2) & 0b0000_0001;
let nolocal = nolocal != 0;

let preserve_retain = options >> 3 & 0b0000_0001;
let preserve_retain = (options >> 3) & 0b0000_0001;
let preserve_retain = preserve_retain != 0;

let retain_forward_rule = (options >> 4) & 0b0000_0011;
Expand Down
2 changes: 1 addition & 1 deletion rumqttc/src/mqttbytes/v4/connect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ impl LastWill {
fn write(&self, buffer: &mut BytesMut) -> Result<u8, Error> {
let mut connect_flags = 0;

connect_flags |= 0x04 | (self.qos as u8) << 3;
connect_flags |= 0x04 | ((self.qos as u8) << 3);
if self.retain {
connect_flags |= 0x20;
}
Expand Down
2 changes: 1 addition & 1 deletion rumqttc/src/mqttbytes/v4/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ impl Publish {
let dup = self.dup as u8;
let qos = self.qos as u8;
let retain = self.retain as u8;
buffer.put_u8(0b0011_0000 | retain | qos << 1 | dup << 3);
buffer.put_u8(0b0011_0000 | retain | (qos << 1) | (dup << 3));

let count = write_remaining_length(buffer, len)?;
write_mqtt_string(buffer, self.topic.as_str());
Expand Down
2 changes: 1 addition & 1 deletion rumqttc/src/v5/mqttbytes/v5/connect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ impl LastWill {
pub fn write(&self, buffer: &mut BytesMut) -> Result<u8, Error> {
let mut connect_flags = 0;

connect_flags |= 0x04 | (self.qos as u8) << 3;
connect_flags |= 0x04 | ((self.qos as u8) << 3);
if self.retain {
connect_flags |= 0x20;
}
Expand Down
2 changes: 1 addition & 1 deletion rumqttc/src/v5/mqttbytes/v5/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ impl Publish {
let dup = self.dup as u8;
let qos = self.qos as u8;
let retain = self.retain as u8;
buffer.put_u8(0b0011_0000 | retain | qos << 1 | dup << 3);
buffer.put_u8(0b0011_0000 | retain | (qos << 1) | (dup << 3));

let count = write_remaining_length(buffer, len)?;
write_mqtt_bytes(buffer, &self.topic);
Expand Down
4 changes: 2 additions & 2 deletions rumqttc/src/v5/mqttbytes/v5/subscribe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,10 @@ impl Filter {
let options = read_u8(bytes)?;
let requested_qos = options & 0b0000_0011;

let nolocal = options >> 2 & 0b0000_0001;
let nolocal = (options >> 2) & 0b0000_0001;
let nolocal = nolocal != 0;

let preserve_retain = options >> 3 & 0b0000_0001;
let preserve_retain = (options >> 3) & 0b0000_0001;
let preserve_retain = preserve_retain != 0;

let retain_forward_rule = (options >> 4) & 0b0000_0011;
Expand Down
22 changes: 17 additions & 5 deletions rumqttc/src/v5/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ impl MqttState {
}
_ => {
warn!("SubAck Pkid = {:?}, Reason = {:?}", suback.pkid, reason);
},
}
}
}
Ok(None)
Expand Down Expand Up @@ -364,7 +364,10 @@ impl MqttState {
if puback.reason != PubAckReason::Success
&& puback.reason != PubAckReason::NoMatchingSubscribers
{
warn!("PubAck Pkid = {:?}, reason: {:?}", puback.pkid, puback.reason);
warn!(
"PubAck Pkid = {:?}, reason: {:?}",
puback.pkid, puback.reason
);
return Ok(None);
}

Expand Down Expand Up @@ -397,7 +400,10 @@ impl MqttState {
if pubrec.reason != PubRecReason::Success
&& pubrec.reason != PubRecReason::NoMatchingSubscribers
{
warn!("PubRec Pkid = {:?}, reason: {:?}", pubrec.pkid, pubrec.reason);
warn!(
"PubRec Pkid = {:?}, reason: {:?}",
pubrec.pkid, pubrec.reason
);
return Ok(None);
}

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

if pubrel.reason != PubRelReason::Success {
warn!("PubRel Pkid = {:?}, reason: {:?}", pubrel.pkid, pubrel.reason);
warn!(
"PubRel Pkid = {:?}, reason: {:?}",
pubrel.pkid, pubrel.reason
);
return Ok(None);
}

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

if pubcomp.reason != PubCompReason::Success {
warn!("PubComp Pkid = {:?}, reason: {:?}", pubcomp.pkid, pubcomp.reason);
warn!(
"PubComp Pkid = {:?}, reason: {:?}",
pubcomp.pkid, pubcomp.reason
);
return Ok(None);
}

Expand Down
2 changes: 1 addition & 1 deletion rumqttd/src/protocol/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ impl Publish {
let dup = self.dup as u8;
let qos = self.qos as u8;
let retain = self.retain as u8;
o.put_u8(0b0011_0000 | retain | qos << 1 | dup << 3);
o.put_u8(0b0011_0000 | retain | (qos << 1) | (dup << 3));
o.put_u16(self.pkid);
o.put_u16(self.topic.len() as u16);
o.extend_from_slice(&self.topic[..]);
Expand Down
2 changes: 1 addition & 1 deletion rumqttd/src/protocol/v4/connect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ mod will {
pub fn write(will: &LastWill, buffer: &mut BytesMut) -> Result<u8, Error> {
let mut connect_flags = 0;

connect_flags |= 0x04 | (will.qos as u8) << 3;
connect_flags |= 0x04 | ((will.qos as u8) << 3);
if will.retain {
connect_flags |= 0x20;
}
Expand Down
2 changes: 1 addition & 1 deletion rumqttd/src/protocol/v4/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ pub fn write(publish: &Publish, buffer: &mut BytesMut) -> Result<usize, Error> {
let dup = publish.dup as u8;
let qos = publish.qos as u8;
let retain = publish.retain as u8;
buffer.put_u8(0b0011_0000 | retain | qos << 1 | dup << 3);
buffer.put_u8(0b0011_0000 | retain | (qos << 1) | (dup << 3));

let count = write_remaining_length(buffer, len)?;
write_mqtt_bytes(buffer, &publish.topic);
Expand Down
2 changes: 1 addition & 1 deletion rumqttd/src/protocol/v5/connect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ mod will {
) -> Result<u8, Error> {
let mut connect_flags = 0;

connect_flags |= 0x04 | (will.qos as u8) << 3;
connect_flags |= 0x04 | ((will.qos as u8) << 3);
if will.retain {
connect_flags |= 0x20;
}
Expand Down
2 changes: 1 addition & 1 deletion rumqttd/src/protocol/v5/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ pub fn write(
let dup = publish.dup as u8;
let qos = publish.qos as u8;
let retain = publish.retain as u8;
buffer.put_u8(0b0011_0000 | retain | qos << 1 | dup << 3);
buffer.put_u8(0b0011_0000 | retain | (qos << 1) | (dup << 3));

let count = write_remaining_length(buffer, len)?;
write_mqtt_bytes(buffer, &publish.topic);
Expand Down
8 changes: 4 additions & 4 deletions rumqttd/src/protocol/v5/subscribe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ pub fn read(
let options = read_u8(&mut bytes)?;
let requested_qos = options & 0b0000_0011;

let nolocal = options >> 2 & 0b0000_0001;
let nolocal = ((options >> 2) & 0b0000_0001);
let nolocal = nolocal != 0;

let preserve_retain = options >> 3 & 0b0000_0001;
let preserve_retain = ((options >> 3) & 0b0000_0001);
let preserve_retain = preserve_retain != 0;

let retain_forward_rule = (options >> 4) & 0b0000_0011;
Expand Down Expand Up @@ -110,10 +110,10 @@ mod filter {
let options = read_u8(bytes)?;
let requested_qos = options & 0b0000_0011;

let nolocal = options >> 2 & 0b0000_0001;
let nolocal = (options >> 2) & 0b0000_0001;
let nolocal = nolocal != 0;

let preserve_retain = options >> 3 & 0b0000_0001;
let preserve_retain = (options >> 3) & 0b0000_0001;
let preserve_retain = preserve_retain != 0;

let retain_forward_rule = (options >> 4) & 0b0000_0011;
Expand Down
5 changes: 1 addition & 4 deletions rumqttd/src/router/iobufs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,7 @@ impl Outgoing {
// Returns (unsolicited, outoforder) flags
// Return: Out of order or unsolicited acks
pub fn register_ack(&mut self, pkid: u16) -> Option<()> {
let (head, _filter_idx, _cursor) = match self.inflight_buffer.pop_front() {
Some(v) => v,
None => return None,
};
let (head, _filter_idx, _cursor) = self.inflight_buffer.pop_front()?;

// We don't support out of order acks
if pkid != head {
Expand Down

0 comments on commit a76d2a0

Please sign in to comment.