Repository: bytebeamio/rumqtt (language: rust)

Issue:
v5 incoming event is boxed?
So in the non-v5 client, he Event struct has a stack allocated Incoming, Outgoing.
In v5, Incoming (but not Outgoing) is boxed.

This makes pattern matching the incoming event in v5 more annoying (and incompatible with the non-v5 one) , because box patterns are not available (and will never be, it looks like rust will try to stabilize deref patterns instead).
As a result, you have to split the match.

IE in non-v5 you can have a match arm of Event::Incoming(Incoming::ConnAck(ack)) 
in v5, you can't, because it would have to be Event::Incoming(box Incoming::ConnAck(ack))

As far as i can tell, there is no totally obvious reason why Incoming is boxed in v5.
Removing the box and updating 3 lines of code to not use boxing still passes all tests, and works fine in my (admittedly simple) app.

Is there a particular reason it's boxed?
If not, i'll send along a pull request to unbox it.



Discussion / hints:

Fix patch:
diff --git a/rumqttc/CHANGELOG.md b/rumqttc/CHANGELOG.md
index 68c1570ab..b8c8b6389 100644
--- a/rumqttc/CHANGELOG.md
+++ b/rumqttc/CHANGELOG.md
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 ### Added
 
 ### Changed
+- Remove `Box` on `Event::Incoming`
 
 ### Deprecated
 
diff --git a/rumqttc/examples/async_manual_acks_v5.rs b/rumqttc/examples/async_manual_acks_v5.rs
index 3131560a1..67d11217d 100644
--- a/rumqttc/examples/async_manual_acks_v5.rs
+++ b/rumqttc/examples/async_manual_acks_v5.rs
@@ -58,7 +58,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
         println!("{event:?}");
 
         if let Event::Incoming(packet) = event {
-            let publish = match *packet {
+            let publish = match packet {
                 Packet::Publish(publish, _) => publish,
                 _ => continue,
             };
diff --git a/rumqttc/src/v5/eventloop.rs b/rumqttc/src/v5/eventloop.rs
index 5f562387c..22a1f0d5c 100644
--- a/rumqttc/src/v5/eventloop.rs
+++ b/rumqttc/src/v5/eventloop.rs
@@ -73,7 +73,7 @@ pub struct EventLoop {
 /// Events which can be yielded by the event loop
 #[derive(Debug, Clone, PartialEq, Eq)]
 pub enum Event {
-    Incoming(Box<Incoming>),
+    Incoming(Incoming),
     Outgoing(Outgoing),
 }
 
@@ -124,7 +124,7 @@ impl EventLoop {
                 self.keepalive_timeout = Some(Box::pin(time::sleep(self.options.keep_alive)));
             }
 
-            return Ok(Event::Incoming(Box::new(connack)));
+            return Ok(Event::Incoming(connack));
         }
 
         match self.select().await {
diff --git a/rumqttc/src/v5/state.rs b/rumqttc/src/v5/state.rs
index 2db33f438..c805ca714 100644
--- a/rumqttc/src/v5/state.rs
+++ b/rumqttc/src/v5/state.rs
@@ -175,7 +175,7 @@ impl MqttState {
         };
 
         out?;
-        self.events.push_back(Event::Incoming(Box::new(packet)));
+        self.events.push_back(Event::Incoming(packet));
         self.last_incoming = Instant::now();
         Ok(())
     }
diff --git a/rumqttd/src/lib.rs b/rumqttd/src/lib.rs
index 172c7ff72..c51ac3168 100644
--- a/rumqttd/src/lib.rs
+++ b/rumqttd/src/lib.rs
@@ -145,8 +145,10 @@ impl ConsoleSettings {
 }
 
 #[derive(Debug, Serialize, Deserialize, Clone)]
+#[derive(Default)]
 pub enum Transport {
     #[serde(rename = "tcp")]
+    #[default]
     Tcp,
     #[serde(rename = "tls")]
     Tls {
@@ -155,11 +157,7 @@ pub enum Transport {
     },
 }
 
-impl Default for Transport {
-    fn default() -> Self {
-        Transport::Tcp
-    }
-}
+
 
 #[derive(Clone, Debug, Serialize, Deserialize)]
 pub struct ClientAuth {


Test patch: