austinjones / postage-rs

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

Only require &self in Sink implementations #42

Closed austinjones closed 3 years ago

austinjones commented 3 years ago

Blockers:

zeenix commented 3 years ago

Not sure this is a good idea if you want your Stream and Sink API to be compatible to what's likely going to be stabilized in std (#23 suggests that you do). I would suggest you add API on top that takes &self and use internal mutability (through a Mutex). Just my two cents as an outsider. :)

austinjones commented 3 years ago

I like that idea! Would be a simple add-on, and it wouldn't complicate the traits...

I've held off on merging this because some sender implementations (particularly combinators) need internal mutable state. For those kind of types, adding an Arc<Mutex> is not good. I thought about implementing Sink for &Self / &mut Self, but Pin requires a reference type when used as self.