thiserror::Error into Box<dyn std::error::Error + Send + Sync>

I have custom result type

pub type Result<T> = std::result::Result<T, Box<dyn std::error::Error + Send + Sync>>;

and custom Error enum based on deriving Error from thiserror

Is there a way to return my error variant as Error of result type above? Issue is with Send and Sync mainly.

How is your custom error defined?

use thiserror::Error;

#[derive(Error, Debug)]
pub enum Error {

And I have to add that I'm able to use it but then 'static lifetime is been auto propagated from somewhere and that causes issues with pin_project_lite::project() as it's used inside Future impl as Output type.
I guess that's the main question but brain is melting a bit... :expressionless:

There should be no issue with using that enum as a boxed error. In what way does your attempt fail?

fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> PollSelf::Output {

  • this data with an anonymous lifetime '_...
    let mut this = self.project();
    ^^^^^^^ captured here, requiring it to live as long as 'static

Please use a code block instead of a quote block.

If I use async_std::io::ErorKind::WriteZero.into() and async_std::io::Result<()> as Output everything works fine but I dont have custom errors anymore.

that's debugger error output, still should be code formatted?

Yes, please put errors in code blocks.

error[E0759]: `self` has an anonymous lifetime `'_` but it needs to satisfy a `'static` lifetime requirement
  --> src/processor/
40 |             fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
   |                           -------------- this data with an anonymous lifetime `'_`...
41 |                 let mut this = self.project();
   |                                     ^^^^^^^ captured here, requiring it to live as long as `'static`

error: aborting due to previous error

I'm going to need to see the full poll function.

PMed you =)

I tried compiling it myself, but got a bunch of errors from the signatures dependency. Did the error include any sort of help message that you cut out?

I will note that your indentation around where bounds is rather unconventional.

nothing else - everything in error above.

Well it sounds like something somewhere is requiring something that derives from this to be 'static, but the error doesn't say what, and I can't run it myself, so I don't think there's much else I am able to do.

Changing Output type to pub type Result<T> = std::result::Result<T, String>; and calling .map_err(|e| e.to_string())? fixes the issue, so it's definitly something with Error enum's lifetime...

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.