No, F
still automatically implements Send
as long as all its data does. So any type that was sendable before will still be sendable.
This change does make it possible to construct ThreadPool<F>
for cases where F
is non-sendable, but generally one prevents by putting the public constructor function, or other required functions, in an impl
block with appropriate bounds. Programs that try to use ThreadPool
with a non-Send
type will still end up getting the same basic error message as before.
The compiler prints two different error messages for the original code, with a “help” suggestion for each error:
help: consider restricting type parameter `F`
|
9 | impl<F: std::ops::FnOnce<(std::net::TcpStream,)>> ThreadPool<F>
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
and:
help: consider restricting type parameter `F`
|
9 | impl<F: std::marker::Send> ThreadPool<F>
| ^^^^^^^^^^^^^^^^^^^
If you apply just one of the suggested fixes, then you'll get a suggestion for how to apply the second one too:
help: consider further restricting this bound
|
9 | impl<F: FnOnce(std::net::TcpStream) + std::marker::Send> ThreadPool<F>
| ^^^^^^^^^^^^^^^^^^^
After applying both suggestions, you end up with this code, which compiles.