Making Result<(), Box<dyn std::error::Error>> thread-safe

I have some async code that I'm trying to further speed up by moving the inner part of a loop into a thread. However, the async block contains a lot of expressions using the ? operator, and the compiler is giving me error E0282 saying type annotations are needed for the return type of the block, and I can't use Result<(), Box<dyn std::error::Error>> because dyn std::error::Error is not Send. Is there a quick and easy way to get around this, especially since I don't intend to use the return values from this async block, or do I have to handle error conditions every place I use the question mark operator?

Please let me know if this is too vague to provide an accurate answer and I'll be happy to give more information or example code.

Use Box<dyn std::error::Error + Send>

2 Likes

The one you want is Box<dyn std::error::Error + Send + Sync>.

Only adding Send causes various types of trouble.

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.