Skip to content

Add no_std support #71

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Kixiron opened this issue Mar 27, 2020 · 2 comments
Closed

Add no_std support #71

Kixiron opened this issue Mar 27, 2020 · 2 comments

Comments

@Kixiron
Copy link

Kixiron commented Mar 27, 2020

It would be great to have no_std support for thiserror, and after a look over the codebase I don't think it would be very difficult, I'm just inexperienced with proc-macros. The only drawbacks (and thus make no_std compatibility require a feature flag) would be that std::error::Error and std::path are not core or alloc friendly. For the most part, migration would be easy as changing std imports to core or alloc, but for the aforementioned roadblocks I propose the following:

Add #![cfg_attr(feature = "no_std", no_std)] to the root of the thiserror crate to enable no_std for the no_std feature
Add a feature to both thiserror and thiserror-impl, possibly something like no_std, this would look about like this

# In thiserror
[features]
default = []
no_std = ["thiserror-impl/no_std"]

# In thiserror-impl
[features]
default = []
no_std = []

And then for problematic areas, like thiserror/src/aserror.rs and thiserror/src/display.rs, simply conditionally compile them when the no_std feature is not active using #[cfg(not(feature = "no_std))]
Lastly there'd be the normal changing std to core/alloc, but adding conditional compilation to places where aserror.rs and display.rs are used would also be needed

@dtolnay
Copy link
Owner

dtolnay commented Mar 27, 2020

Closing in favor of #64 to keep the discussion in one place.

@dtolnay dtolnay closed this as completed Mar 27, 2020
@Kixiron
Copy link
Author

Kixiron commented Mar 27, 2020

Oh, I'm sorry, I didn't see that PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants