austinjones / postage-rs

The feature-rich, portable async channel library
MIT License
252 stars 9 forks source link

Only &mut send methods are available for sending to channels #38

Closed arthurprs closed 2 years ago

arthurprs commented 3 years ago

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).

austinjones commented 3 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.

austinjones commented 2 years ago

I've been preparing a v0.5 release, and I think I need to keep &mut. There are a few reasons:

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.