pub async fn subscribe<C: Fn(&crate::client::TopicEvent) + Send + Sync + 'static>(self, callback: C) -> Result<()> {
        let client = get_mqtt_client(self.client).await?;
        let cb = Arc::new(Box::new(callback) as Box<dyn Fn(&crate::client::TopicEvent) + Send + Sync + 'static>);
        client
            .subscribe_many(
                self.topics
                    .iter()
                    .map(|t| SubscribeFilter::new(t.0.clone(), QoS::AtLeastOnce))
                    .collect::<Vec<SubscribeFilter>>(),
            )
            .await?;
        {
            let mqtt_topic_handlers = &self.client.mqtt_topic_handlers;
            let mut mqtt_topic_handlers = mqtt_topic_handlers.write().await;
            for topic in self.topics {
                match mqtt_topic_handlers.get_mut(&topic) {
                    Some(handlers) => handlers.push(cb.clone()),
                    None => {
                        mqtt_topic_handlers.insert(topic, vec![cb.clone()]);
                    }
                }
            }
        }
        Ok(())
    }
/// Subscribe to the given topics with the callback.
Subscribe to the given topics with the callback.
Subscribe to the given topics with the callback .
pub async fn subscribe<C: Fn(&crate::client::TopicEvent) + Send + Sync + 'static>(self, callback: C) -> Result<()> {
        let client = get_mqtt_client(self.client).await?;
        let cb = Arc::new(Box::new(callback) as Box<dyn Fn(&crate::client::TopicEvent) + Send + Sync + 'static>);
        client
            .subscribe_many(
                self.topics
                    .iter()
                    .map(|t| SubscribeFilter::new(t.0.clone(), QoS::AtLeastOnce))
                    .collect::<Vec<SubscribeFilter>>(),
            )
            .await?;
        {
            let mqtt_topic_handlers = &self.client.mqtt_topic_handlers;
            let mut mqtt_topic_handlers = mqtt_topic_handlers.write().await;
            for topic in self.topics {
                match mqtt_topic_handlers.get_mut(&topic) {
                    Some(handlers) => handlers.push(cb.clone()),
                    None => {
                        mqtt_topic_handlers.insert(topic, vec![cb.clone()]);
                    }
                }
            }
        }
        Ok(())
    }
pub async fn subscribe < C : Fn ( & crate :: client :: TopicEvent ) + Send + Sync + ' static > ( self , callback : C ) -> Result < ( ) > { let client = get_mqtt_client ( self . client ) . await ? ; let cb = Arc :: new ( Box :: new ( callback ) as Box < dyn Fn ( & crate :: client :: TopicEvent ) + Send + Sync + ' static > ) ; client . subscribe_many ( self . topics . iter ( ) . map ( | t | SubscribeFilter :: new ( t . 0 . clone ( ) , QoS :: AtLeastOnce ) ) . collect :: < Vec < SubscribeFilter > > ( ) , ) . await ? ; { let mqtt_topic_handlers = & self . client . mqtt_topic_handlers ; let mut mqtt_topic_handlers = mqtt_topic_handlers . write ( ) . await ; for topic in self . topics { match mqtt_topic_handlers . get_mut ( & topic ) { Some ( handlers ) => handlers . push ( cb . clone ( ) ) , None => { mqtt_topic_handlers . insert ( topic , vec ! [ cb clone ( ) ] ) ; } } } } Ok ( ( ) ) }
Subscribe to the given topics with the callback.
Subscribe to the given topics with the callback .
self
callback
C
self
callback
C