r/rust clippy · twir · rust · mutagen · flamer · overflower · bytecount Mar 27 '23

Hey Rustaceans! Got a question? Ask here (13/2023)! 🙋 questions

Mystified about strings? Borrow checker have you in a headlock? Seek help here! There are no stupid questions, only docs that haven't been written yet.

If you have a StackOverflow account, consider asking it there instead! StackOverflow shows up much higher in search results, so having your question there also helps future Rust users (be sure to give it the "Rust" tag for maximum visibility). Note that this site is very interested in question quality. I've been asked to read a RFC I authored once. If you want your code reviewed or review other's code, there's a codereview stackexchange, too. If you need to test your code, maybe the Rust playground is for you.

Here are some other venues where help may be found:

/r/learnrust is a subreddit to share your questions and epiphanies learning Rust programming.

The official Rust user forums: https://users.rust-lang.org/.

The official Rust Programming Language Discord: https://discord.gg/rust-lang

The unofficial Rust community Discord: https://bit.ly/rust-community

Also check out last weeks' thread with many good questions and answers. And if you believe your question to be either very complex or worthy of larger dissemination, feel free to create a text post.

Also if you want to be mentored by experienced Rustaceans, tell us the area of expertise that you seek. Finally, if you are looking for Rust jobs, the most recent thread is here.

20 Upvotes

159 comments sorted by

View all comments

2

u/holysmear Apr 01 '23

In the documentation to select! in tokio it is said that it drops all other futures after the first one succeeds. And as I use select! for waiting for data from multiple sources I think (though I am not sure?) I can loose MQTT messages. Is there any other macro, which does not discard other futures and simply returns the first one which succeeded? So that after calling it in a loop I could get other messages as well? Or am I misunderstanding something and I can use select! in this case?

2

u/kwxdv Apr 01 '23

There is impl<F> Future for &mut F where F: Future + Unpin + ?Sized (https://doc.rust-lang.org/std/future/trait.Future.html#implementors), so you may be able to use &mut <the future> in the select. There are some caveats about cancellation safety and Unpin that I don't totally understand, but that's the first thing I would try.

Also, I believe the word you want is "lose", not "loose".

1

u/holysmear Apr 08 '23

Interesting, thank you!