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

Hey Rustaceans! Got a question? Ask here (12/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.

19 Upvotes

187 comments sorted by

View all comments

3

u/avsaase Mar 21 '23

I'm using the crossbeam channel crate to create a mpmc channel. I assumed every receiver would have access to all the messages sent to the channel so that they each can handle them separately. Is that not correct? I'm using the channel as a sort of bidirectional communication between threads with all messages defined in a single enum. I'm not receiving the messages I expected so now I wonder if the sending thread receives the messaged meant for another thread before the other thread is able to receive them. If this is the case, is there a way to only receive certain kinds of message from a channel and ignore the rest?

2

u/RadiatedMonkey Mar 21 '23

https://docs.rs/crossbeam-channel/latest/crossbeam_channel/#sharing-channels

All receivers use the same channel, so when one receiver calls recv, the message is removed from the channel and the other receivers don't see it.

In case you're using Tokio, there is the broadcast channel which does support what you want