Is it possible to implement `Sync` for `std::sync::mpsc::Sender`?

Recently std::sync::mpsc was internally replaced with an implementation backed by crossbeam-channels in PR #93563. Someone from my work pointed out that that there is still an API difference:

impl<T: Send> Sync for crossbeam_channel::Sender<T>


impl<T> !Sync for std::sync::mpsc::Sender<T>


  • Would it be possible to replace the !Sync implementation with the same one from crossbeam_channel without backwards compatibility concerns?
  • Is there any existing work to find differences in the APIs of crossbeam_channel and std::sync::mpsc and bring them closer together?

There are other differences, like impl Clone for Receiver in crossbeam-channel but not in std::sync::mpsc. These are because changing the API surface area would be a breaking change.

The linked PR left open the option to add mpmc to the standard library, which also means that adding these extra impls is at least on the table for a potential new channel type in the future.

I didn't really answer your question. That's because I don't really know the answer. It seems like impl Sync for Sender and impl Clone for Receiver would not cause breakage since these traits loosen restrictions (they are purely additive). But I don't personally know all the weird and wacky ways that combinatorial traits behave!

1 Like

I think we could safely add those things, but it becomes part of the API contract, so we could never go back. If one supposes there may be an even better implementation in the future that can't support those things, that could be unfortunate to be locked out -- but this is hypothetical.


This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.