diff --git a/mqtt-v5-broker/src/broker.rs b/mqtt-v5-broker/src/broker.rs index e6d2cf5..67e5a15 100644 --- a/mqtt-v5-broker/src/broker.rs +++ b/mqtt-v5-broker/src/broker.rs @@ -340,7 +340,7 @@ impl Broker { // Unsubscribe the old session from all topics it subscribed to. session.subscription_tokens.retain(|(session_topic, token)| { if *session_topic == *topic { - subscriptions.remove(&session_topic, *token); + subscriptions.remove(session_topic, *token); false } else { true @@ -391,7 +391,7 @@ impl Broker { // Unsubscribe the old session from all topics it subscribed to. session.subscription_tokens.retain(|(session_topic, token)| { if *session_topic == *filter { - subscriptions.remove(&session_topic, *token); + subscriptions.remove(session_topic, *token); false } else { true diff --git a/mqtt-v5-broker/src/tree.rs b/mqtt-v5-broker/src/tree.rs index 632ca49..26aa331 100644 --- a/mqtt-v5-broker/src/tree.rs +++ b/mqtt-v5-broker/src/tree.rs @@ -68,35 +68,27 @@ impl SubscriptionTreeNode { for level in topic_filter.levels() { match level { TopicLevel::SingleLevelWildcard => { - if current_tree.single_level_wildcards.is_some() { - current_tree = current_tree.single_level_wildcards.as_mut().unwrap(); - } else { + if current_tree.single_level_wildcards.is_none() { current_tree.single_level_wildcards = Some(Box::new(SubscriptionTreeNode::new())); - current_tree = current_tree.single_level_wildcards.as_mut().unwrap(); } + + current_tree = current_tree.single_level_wildcards.as_mut().unwrap(); }, TopicLevel::MultiLevelWildcard => { multi_level = true; break; }, TopicLevel::Concrete(concrete_topic_level) => { - if current_tree.concrete_topic_levels.contains_key(concrete_topic_level) { - current_tree = current_tree - .concrete_topic_levels - .get_mut(concrete_topic_level) - .unwrap(); - } else { + if !current_tree.concrete_topic_levels.contains_key(concrete_topic_level) { current_tree .concrete_topic_levels .insert(concrete_topic_level.to_string(), SubscriptionTreeNode::new()); - - // TODO - Do this without another hash lookup - current_tree = current_tree - .concrete_topic_levels - .get_mut(concrete_topic_level) - .unwrap(); } + + // TODO - Do this without another hash lookup + current_tree = + current_tree.concrete_topic_levels.get_mut(concrete_topic_level).unwrap(); }, } } diff --git a/mqtt-v5/src/encoder.rs b/mqtt-v5/src/encoder.rs index 2f91ad9..cc0d3ff 100644 --- a/mqtt-v5/src/encoder.rs +++ b/mqtt-v5/src/encoder.rs @@ -271,11 +271,11 @@ fn encode_connect(packet: &ConnectPacket, bytes: &mut BytesMut, protocol_version } if let Some(user_name) = &packet.user_name { - encode_string(&user_name, bytes); + encode_string(user_name, bytes); } if let Some(password) = &packet.password { - encode_string(&password, bytes); + encode_string(password, bytes); } }