derive-error icon indicating copy to clipboard operation
derive-error copied to clipboard

no_std use

Open fluffysquirrels opened this issue 6 years ago • 1 comments

I love this crate and use it for error handling in all my projects that run with the standard library. I recently worked on an embedded project with no_std enabled: so no standard library (std), no std::error::Error, no heap allocator, no String. I still wanted From implementations for my crate's Error enum but ended up writing them by hand.

Any thoughts on supporting a no_std mode, perhaps configured with a #[error(no_std)] attribute on the Error enum? Would you be willing to work on this or accept PRs for this feature?

I think the implementation would change slightly here but could be as simple as: when no_std, output ::core::fmt instead of ::std::fmt for the Display impl, and implement description as a local method rather than a trait method, removing the ::std::error::Error block entirely.

fluffysquirrels avatar Jan 06 '18 19:01 fluffysquirrels

I've always wanted to add no_std support. It's just that I haven't had a strong motivation to do it so far as all the projects I'm working on run in environments where the standard library is available. So yes, I would totally appreciate a PR.

rushmorem avatar Jan 07 '18 15:01 rushmorem