From f50bc4bd0c54519c96b43f0781f22b9129112f62 Mon Sep 17 00:00:00 2001 From: Dreaded_X Date: Sun, 5 May 2024 00:33:21 +0200 Subject: [PATCH] Replaced impl_cast with a new and improved trait With this trait the impl_cast macros are no longer needed, simplifying everything. This commit also improved how the actual casting itself is handled. --- src/device_manager.rs | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/src/device_manager.rs b/src/device_manager.rs index 0a1833a..cbbe12d 100644 --- a/src/device_manager.rs +++ b/src/device_manager.rs @@ -142,17 +142,14 @@ impl DeviceManager { debug!(id, "Adding device"); - { - // If the device listens to mqtt, subscribe to the topics - let device: Option<&dyn OnMqtt> = device.as_ref().cast(); - if let Some(device) = device { - for topic in device.topics() { - trace!(id, topic, "Subscribing to topic"); - if let Err(err) = self.client.subscribe(topic, QoS::AtLeastOnce).await { - // NOTE: Pretty sure that this can only happen if the mqtt client if no longer - // running - error!(id, topic, "Failed to subscribe to topic: {err}"); - } + // If the device listens to mqtt, subscribe to the topics + if let Some(device) = device.as_ref().cast() as Option<&dyn OnMqtt> { + for topic in device.topics() { + trace!(id, topic, "Subscribing to topic"); + if let Err(err) = self.client.subscribe(topic, QoS::AtLeastOnce).await { + // NOTE: Pretty sure that this can only happen if the mqtt client if no longer + // running + error!(id, topic, "Failed to subscribe to topic: {err}"); } } }