Skip to content
This repository has been archived by the owner on Aug 16, 2021. It is now read-only.

Replace std::error::Error with core_error::Error #334

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

roblabla
Copy link

@roblabla roblabla commented Nov 2, 2019

Fixes #328

Use core_error::Error, a compatibility Error trait in no_std environment allowing interoperability between various error handling crates, such as snafu. In std environment, core_error simply reexports std::error, so this change should be invisible to std users.

In particular this change does two things:

  • It implements Fail on every core_error::Error error.
  • It implements core_error::Error on Compat.

It also replaces other usage of std::error::Error to core_error::Error, but those should have no visible effect.

This is a preliminary PR to get some feedback. In particular, I'm not sure where to document the changes. no_std documentation is pretty scarce in failure.

To promote compatibility across error-handling crates, use
core_error::Error as the StdError trait. When using the std feature,
core_error simply reexports the std crate. Otherwise, it provide its own
Error trait with all the std-only features removed, and implements the
trait on all the error structs found in libcore.

This PR brings two immediate benefits to no_std users: It makes the Compat
struct into a proper compatibility layer, and it makes the core errors
compatible with the Fail trait.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Collaborate on a "core::Error" crate with snafu, anyhow and other error crates
1 participant