How to use get the payload of a rumqtt MQTT message outside of the callback closure


#1

I have the following code where I am able to get and print the topic and payload from a message:

let callback = |msg: rumqtt::Message| {
let t = &msg.topic.as_str();
let s = String::from_utf8_lossy(&msg.payload);
println!(“Topic = {}”, t);
println!(“Received payload: {}”, s);
};

let mq_cbs = MqttCallback::new().on_message(callback);

The question is how can I get the topic and payload outside of the closure?


#2

Is there a reason you are repeating your question?
You had quite an active topic going on already :slight_smile:

If you are looking for quicker, more interactive, feedback, the #rust-beginners chatroom might be more useful for you.


#3