The signatures for Sender::send and JoinHandle::join are, respectively:
pub fn send(&self, t: T) -> Result<(), SendError<T>>
pub fn join(self) -> Result<T, Box<dyn Any + Send + 'static>>
Since SendError implements Send and Any and owns its content, this should work:
pub fn finish(
tx: std::sync::mpsc::Sender<()>,
jh: std::thread::JoinHandle<()>,
) -> Result<(), Box<dyn std::any::Any + Send + 'static>> {
tx.send(())?;
jh.join()?;
Ok(())
}
but it fails with the trait From<SendError<()>> is not implemented for Box<dyn Any + Send>.
Why is there a constraint failure and how does the function signature need to change to have it compile?
Would like to not use external libraries.
unwrapthe result of callingjoin. This will only beErrif the thread panicked, and in that case it may make more sense to propagate the panic as a panic anyway.