Skip to content

Commit

Permalink
Cargo clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
bschwind committed Jan 24, 2020
1 parent a1318fb commit 1b4b67e
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 32 deletions.
8 changes: 4 additions & 4 deletions src/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -743,7 +743,7 @@ fn decode_publish_complete(
fn decode_subscribe(
bytes: &mut Cursor<&mut BytesMut>,
remaining_packet_length: u32,
protocol_version: &ProtocolVersion,
protocol_version: ProtocolVersion,
) -> Result<Option<Packet>, DecodeError> {
let start_cursor_pos = bytes.position();

Expand All @@ -752,7 +752,7 @@ fn decode_subscribe(
let mut subscription_identifier = None;
let mut user_properties = vec![];

if *protocol_version == ProtocolVersion::V500 {
if protocol_version == ProtocolVersion::V500 {
return_if_none!(decode_properties(bytes, |property| {
match property {
Property::SubscriptionIdentifier(p) => subscription_identifier = Some(p),
Expand Down Expand Up @@ -1016,7 +1016,7 @@ fn decode_authenticate(
}

fn decode_packet(
protocol_version: &ProtocolVersion,
protocol_version: ProtocolVersion,
packet_type: &PacketType,
bytes: &mut Cursor<&mut BytesMut>,
remaining_packet_length: u32,
Expand All @@ -1043,7 +1043,7 @@ fn decode_packet(

pub fn decode_mqtt(
bytes: &mut BytesMut,
protocol_version: &ProtocolVersion,
protocol_version: ProtocolVersion,
) -> Result<Option<Packet>, DecodeError> {
let mut bytes = Cursor::new(bytes);
let first_byte = read_u8!(bytes);
Expand Down
30 changes: 15 additions & 15 deletions src/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ mod tests {

let mut bytes = BytesMut::new();
encode_mqtt(&packet, &mut bytes);
let decoded = decode_mqtt(&mut bytes, &ProtocolVersion::V500).unwrap().unwrap();
let decoded = decode_mqtt(&mut bytes, ProtocolVersion::V500).unwrap().unwrap();

assert_eq!(packet, decoded);
}
Expand Down Expand Up @@ -562,7 +562,7 @@ mod tests {

let mut bytes = BytesMut::new();
encode_mqtt(&packet, &mut bytes);
let decoded = decode_mqtt(&mut bytes, &ProtocolVersion::V500).unwrap().unwrap();
let decoded = decode_mqtt(&mut bytes, ProtocolVersion::V500).unwrap().unwrap();

assert_eq!(packet, decoded);
}
Expand Down Expand Up @@ -591,7 +591,7 @@ mod tests {

let mut bytes = BytesMut::new();
encode_mqtt(&packet, &mut bytes);
let decoded = decode_mqtt(&mut bytes, &ProtocolVersion::V500).unwrap().unwrap();
let decoded = decode_mqtt(&mut bytes, ProtocolVersion::V500).unwrap().unwrap();

assert_eq!(packet, decoded);
}
Expand All @@ -608,7 +608,7 @@ mod tests {

let mut bytes = BytesMut::new();
encode_mqtt(&packet, &mut bytes);
let decoded = decode_mqtt(&mut bytes, &ProtocolVersion::V500).unwrap().unwrap();
let decoded = decode_mqtt(&mut bytes, ProtocolVersion::V500).unwrap().unwrap();

assert_eq!(packet, decoded);
}
Expand All @@ -625,7 +625,7 @@ mod tests {

let mut bytes = BytesMut::new();
encode_mqtt(&packet, &mut bytes);
let decoded = decode_mqtt(&mut bytes, &ProtocolVersion::V500).unwrap().unwrap();
let decoded = decode_mqtt(&mut bytes, ProtocolVersion::V500).unwrap().unwrap();

assert_eq!(packet, decoded);
}
Expand All @@ -642,7 +642,7 @@ mod tests {

let mut bytes = BytesMut::new();
encode_mqtt(&packet, &mut bytes);
let decoded = decode_mqtt(&mut bytes, &ProtocolVersion::V500).unwrap().unwrap();
let decoded = decode_mqtt(&mut bytes, ProtocolVersion::V500).unwrap().unwrap();

assert_eq!(packet, decoded);
}
Expand All @@ -659,7 +659,7 @@ mod tests {

let mut bytes = BytesMut::new();
encode_mqtt(&packet, &mut bytes);
let decoded = decode_mqtt(&mut bytes, &ProtocolVersion::V500).unwrap().unwrap();
let decoded = decode_mqtt(&mut bytes, ProtocolVersion::V500).unwrap().unwrap();

assert_eq!(packet, decoded);
}
Expand All @@ -683,7 +683,7 @@ mod tests {

let mut bytes = BytesMut::new();
encode_mqtt(&packet, &mut bytes);
let decoded = decode_mqtt(&mut bytes, &ProtocolVersion::V500).unwrap().unwrap();
let decoded = decode_mqtt(&mut bytes, ProtocolVersion::V500).unwrap().unwrap();

assert_eq!(packet, decoded);
}
Expand All @@ -701,7 +701,7 @@ mod tests {

let mut bytes = BytesMut::new();
encode_mqtt(&packet, &mut bytes);
let decoded = decode_mqtt(&mut bytes, &ProtocolVersion::V500).unwrap().unwrap();
let decoded = decode_mqtt(&mut bytes, ProtocolVersion::V500).unwrap().unwrap();

assert_eq!(packet, decoded);
}
Expand All @@ -718,7 +718,7 @@ mod tests {

let mut bytes = BytesMut::new();
encode_mqtt(&packet, &mut bytes);
let decoded = decode_mqtt(&mut bytes, &ProtocolVersion::V500).unwrap().unwrap();
let decoded = decode_mqtt(&mut bytes, ProtocolVersion::V500).unwrap().unwrap();

assert_eq!(packet, decoded);
}
Expand All @@ -736,7 +736,7 @@ mod tests {

let mut bytes = BytesMut::new();
encode_mqtt(&packet, &mut bytes);
let decoded = decode_mqtt(&mut bytes, &ProtocolVersion::V500).unwrap().unwrap();
let decoded = decode_mqtt(&mut bytes, ProtocolVersion::V500).unwrap().unwrap();

assert_eq!(packet, decoded);
}
Expand All @@ -746,7 +746,7 @@ mod tests {
let packet = Packet::PingRequest;
let mut bytes = BytesMut::new();
encode_mqtt(&packet, &mut bytes);
let decoded = decode_mqtt(&mut bytes, &ProtocolVersion::V500).unwrap().unwrap();
let decoded = decode_mqtt(&mut bytes, ProtocolVersion::V500).unwrap().unwrap();

assert_eq!(packet, decoded);
}
Expand All @@ -756,7 +756,7 @@ mod tests {
let packet = Packet::PingResponse;
let mut bytes = BytesMut::new();
encode_mqtt(&packet, &mut bytes);
let decoded = decode_mqtt(&mut bytes, &ProtocolVersion::V500).unwrap().unwrap();
let decoded = decode_mqtt(&mut bytes, ProtocolVersion::V500).unwrap().unwrap();

assert_eq!(packet, decoded);
}
Expand All @@ -773,7 +773,7 @@ mod tests {
});
let mut bytes = BytesMut::new();
encode_mqtt(&packet, &mut bytes);
let decoded = decode_mqtt(&mut bytes, &ProtocolVersion::V500).unwrap().unwrap();
let decoded = decode_mqtt(&mut bytes, ProtocolVersion::V500).unwrap().unwrap();

assert_eq!(packet, decoded);
}
Expand All @@ -790,7 +790,7 @@ mod tests {
});
let mut bytes = BytesMut::new();
encode_mqtt(&packet, &mut bytes);
let decoded = decode_mqtt(&mut bytes, &ProtocolVersion::V500).unwrap().unwrap();
let decoded = decode_mqtt(&mut bytes, ProtocolVersion::V500).unwrap().unwrap();

assert_eq!(packet, decoded);
}
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ impl MqttCodec {

pub fn decode(&mut self, buf: &mut BytesMut) -> Result<Option<Packet>, DecodeError> {
// TODO - Ideally we should keep a state machine to store the data we've read so far.
let packet = decoder::decode_mqtt(buf, &self.version);
let packet = decoder::decode_mqtt(buf, self.version);

if let Ok(Some(Packet::Connect(packet))) = &packet {
self.version = packet.protocol_version;
Expand Down
6 changes: 3 additions & 3 deletions src/topic/mod.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
const TOPIC_SEPARATOR: char = '/';

const MULTI_LEVEL_WILDCARD: char = '#';
const MULTI_LEVEL_WILDCARD_STR: &'static str = "#";
const MULTI_LEVEL_WILDCARD_STR: &str = "#";

const SINGLE_LEVEL_WILDCARD: char = '+';
const SINGLE_LEVEL_WILDCARD_STR: &'static str = "+";
const SINGLE_LEVEL_WILDCARD_STR: &str = "+";

const SHARED_SUBSCRIPTION_PREFIX: &'static str = "$share/";
const SHARED_SUBSCRIPTION_PREFIX: &str = "$share/";

pub const MAX_TOPIC_LEN_BYTES: usize = 65_535;

Expand Down
17 changes: 8 additions & 9 deletions src/topic/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ impl<T: std::fmt::Debug> SubscriptionTreeNode<T> {
}

fn is_empty(&self) -> bool {
return self.subscribers.is_empty()
self.subscribers.is_empty()
&& self.single_level_wildcards.is_none()
&& self.multi_level_wildcards.is_empty()
&& self.concrete_topic_levels.is_empty();
&& self.concrete_topic_levels.is_empty()
}

fn insert(&mut self, topic_filter: &TopicFilter, value: T, counter: u64) {
Expand Down Expand Up @@ -163,13 +163,12 @@ impl<T: std::fmt::Debug> SubscriptionTreeNode<T> {
} else {
None
}
} else if let Some(pos) =
current_tree.subscribers.iter().position(|(c, _)| *c == counter)
{
Some(current_tree.subscribers.remove(pos))
} else {
if let Some(pos) = current_tree.subscribers.iter().position(|(c, _)| *c == counter)
{
Some(current_tree.subscribers.remove(pos))
} else {
None
}
None
}
};

Expand All @@ -190,7 +189,7 @@ impl<T: std::fmt::Debug> SubscriptionTreeNode<T> {
},
TopicLevel::Concrete(concrete_topic_level) => {
if let Entry::Occupied(o) =
tree.concrete_topic_levels.entry(concrete_topic_level.to_string())
tree.concrete_topic_levels.entry((*concrete_topic_level).to_string())
{
if o.get().is_empty() {
o.remove_entry();
Expand Down

0 comments on commit 1b4b67e

Please sign in to comment.