If you believe taking
&self is safe, then do it. No reason to arbitrarily require
&mut self if it isn’t actually required.
mpsc::Receiver is protected from multiple calls to
Receiver not implementing
impl<T> !Sync for Receiver<T> in https://doc.rust-lang.org/std/sync/mpsc/struct.Receiver.html).
The only reasons you would want to take
&mut self instead of
- if your code is unsound if it were implemented using
&self. In particular, interior mutability on anything outside an
UnsafeCell or atomic is unsound, so if taking
&self requires you to do that then that’s a good reason to take
&mut self instead.
&self allows users to use it in a way you believe will be incorrect the majority of the time.
I don’t see either of these being true, so I would just keep
&self. But I haven’t looked at the code in depth so my assessment could be incorrect.
Edit: It looks like
BareSubscriber is sync (
impl<T> Sync for BareSubscriber<T> is in the documentation), so your current method taking
&self will allow two threads to call
try_recv at the same time. If you think this will cause problems, even if it doesn’t cause unsoundness, I would recommend taking
&mut self. If it will do the right thing no matter how many threads are accessing it concurrently, then no matter. Since
Clone, I assume that the latter is true.