tailhook/quick-error

Feature request: impl From<Context<...>> for ExternError

leoleoasd opened this issue · 1 comments

Sometimes we need to wrap our error into a ExternError:

impl From<MyError> for ExternError{
    fn from(err: MyError) -> Self {
        ExternError::Other(Box::new(err))
    }
}

But this can't be implemented for Context on our side, making the usage of ? operator on a Context isn't possible.
It would be awesome to have something like this:

quick_error! {
    #[derive(Debug)]
    pub enum MyError{
        SomeError(name: String, err: AError) {
            display(...)
            context(text: String, err: AError) -> (text, err)
        }
        ....
    },
    from(err: MyError) -> { // A block, will be called in from<myerror> and from<context>
        ExternError::Other(Box::new(err))
    }
}
// generates following code:
....

impl From<MyError> for ExternError {
    fn from(err: MyError) -> Self {
        ExternError::Other(Box::new(err))
    }
}
impl<'a> From<$crate::Context<String, EscapeError>> for ExternError {
    fn from($crate::Context(name, err): $crate::Context<String, AError>) -> ExternError {
        ExternError::from(MyError::SomeError(name, err));
    }
}

This turns out to be impossible because both Context and ExternError are extern structs.