Why doesn't the generic parameter T of std::sync::mpsc::Sender have a Send bound?

While exploring the standard library source code, I found that the channel itself does not impose any restrictions on T . However, when attempting to send a type that is !Send , the error occurs in the closure code. Why is this the case?

1 Like
1 Like

If the message type is not Send, then the sender and receiver also won't be Send. This means that the sender and receiver will always be on the same thread. You can still send messages, but you cannot use the channel to send message to another thread.

You probably got an error because you attempted to move the sender or receiver to another thread.

@theemathas That post isn't relevant here. There aren't Send bounds on the impl blocks either.

11 Likes