Skip to content

Add no_std support #71

@Kixiron

Description

@Kixiron

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions