Closed arthurprs closed 2 years ago
This is an interesting one. Other Sink traits take Pin<&mut Self>
, but it does seem like channels should only require Pin<&Self>
. I think I might be able to change the Sink signature to not require &mut, because the postage Sink trait won't typically be implemented for I/O types.
I've been preparing a v0.5 release, and I think I need to keep &mut
. There are a few reasons:
&self
(mpsc) are wrapped with implementations that require &mut self. &mut
is required. mut
tags make it clear whether the channel will be modified, or just passed along/ignored.std::Stream/Sink
when those are written. I think they are likely to require&mut
.The only workaround I see is a helper that wraps with a Mutex. But it wouldn't integrate well with the library, because if it implemented Sink/Stream
it would again require &mut
.
I'm going to close this for now. But if anyone has fresh ideas it could be re-opened.
It's widely spread that multi producer channels (eg. mpsc, broadcast, ...)
send()
methods are &self, as seen in other channel and runtime libraries.Since sending is only practically accessible with
postage::sink::Sink::send(&mut, ..)
it forces the users trying to use postage channels to use.clone().send(..)
instead, or wrap it with a Mutex (worse), or refactor code around this requirement (maybe worse).