eclipse / paho.mqtt.rust

paho.mqtt.rust
Other
518 stars 102 forks source link

Question: moving received message out from async callback? #90

Closed braincow closed 3 years ago

braincow commented 4 years ago

Hi,

On line 161 in my code here: https://github.com/braincow/maws2iotcore/blob/a028d5753fed5e986e038fa2e1a324d2a8e2c245/src/lib/iotcore.rs#L161 when I try to move a received message out from the enclosure of the callback I get a lifetime issue:

error: cannot infer an appropriate lifetime
   --> src/lib/iotcore.rs:156:24
    |
156 |     async fn subscribe(&self) -> Result<(), mqtt::Error> {
    |                        ^^^^^
    |                        |
    |                        data with this lifetime...
    |                        ...is captured here...
...
161 |         self.client.set_message_callback(move |_cli, msg| {
    |                     -------------------- ...and required to be `'static` by this

What would be the preferred way of moving messages out of the enclosure in this case or am I missing something in the docs on how to accomplish this in proper async way?

fpagliughi commented 4 years ago

Hmm. Is the compiler complaining that it can't tell if the lifetime of your IotCoreClient is sufficient for a callback? I can look into it.

fpagliughi commented 3 years ago

Closing from no activity.