Skip to content

Error converting Box<Error+Send> to &Error #19279

Description

@emk

I'm trying to write an Error implementation which supports a set of "important" error, plus a catch-all for various minor errors caused by low-level subsystems. The code looks something like this:

use std::error::Error;

pub enum DecodingError {
    EncodingUnknown,
    //...several named errors here...
    /// Other errors, the details of which are probably unimportant.
    Unexpected(Box<Error+Send>)
}

impl Error for DecodingError {
    fn description(&self) -> &str { "decoding error" }
    fn detail(&self) -> Option<String> { None }
    fn cause(&self) -> Option<&Error> {
        match self {
            &DecodingError::Unexpected(cause) => Some(&*cause),
            _ => None
        }
    }
}

This yields the following error in cause:

:14:9: 17:10 error: mismatched types: expected core::option::Option<&std::error::Error+'static>, found core::option::Option<&std::error::Error+Send> (expected no bounds, found Send)

I should presumably be able to convert a Box<Error+Send> to an &Error safely, but I can't figure out a way to do it.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions