Convert errors to Box<Error + Send>

With the help of ? operator most errors are easily convertible to Box<Error>, and I’ve used that type extensively. Now I need to return these errors from another thread, so I’ve changed error types to Box<Error + Send>.

However, Err("foo")? used to convert seamlessly to Box<Error>, but it doesn’t convert to Box<Error + Send>. In general I have a problem with Rust being picky about converting various types that have Error and I suppose should be Send to Box<Error + Send>.

Is Rust missing a From/Into implementations for the + Send versions? How can I easily covert sendable types that implement Error to to Result<(), Box<Error + Send>>?

1 Like

There are From impls for Box<Error> and Box<Error + Send + Sync>, but not for Box<Error + Send>. So, just add Sync :slight_smile:


Thanks. What about compatibility of Box<Error + Send + Sync> with plain Box<Error>?

This seems like an issue with impl<T: Error> From<T> for Box<Error> needing T to be Sized since ? ends up calling into() on the error. In fact, if you hand wrote the match code as follows, it works:

fn all() -> Result<(), Box<Error + Send + Sync>> {

fn one() -> Result<(), Box<Error>> {
    match all() {
      Ok(()) => Ok(()),
      Err(e) => Err(e)

But of course if you change Err(e) => Err(e) to Err(e) => Err(e.into()), you get the same compilation error.

1 Like

Oh my god, thank you, I have started pulling my hair out

1 Like