Skip to content

recommend core::error::Error for ErrorType::Error #633

@jordens

Description

@jordens

As of #630 the ErrorKind structs implement Error.
As explained in #630 (comment)
its difficult to make good use of that unless the e-h traits add a core::error::Error bound to their ErrorType::Error type:
A device driver that uses a e-h trait wants to return the hal's Error from its impl of core::error::Error::source() -> Option<&dyn core::error::Error>. Returning the ErrorKind is hard/annoying/inefficient due to the need to store it. The "good" way to do that is appears to either require core::error::Error for the hal's Errors or for each device driver to implement newtype wrappers for any hal Error (which are then limited as they can only rely on Error::kind() and Debug).
Adding that bound is obviously breaking. But the burden is manageable: (1) the MSRV bump is already there (2) a trivial impl of core::error::Error will always be sufficient and in most cases even complete (3) thiserror and other crates make the job easy.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions