Skip to content
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

Allow opt-in to no_std implementations #11

Open
chrysn opened this issue Nov 28, 2019 · 1 comment
Open

Allow opt-in to no_std implementations #11

chrysn opened this issue Nov 28, 2019 · 1 comment

Comments

@chrysn
Copy link

chrysn commented Nov 28, 2019

The use of std::process::catch_unwind and abort makes this crate (and all that depend on it) unusable for embedded systems.

The same guarantee the "catch_unwind or abort" mechanism gives can be achieved without that as suggested by @rkruppe in rust-lang/rfcs#2810 (comment) by placing a ZST on the stack, mem::forgetting it in the regular case and aborting in its Drop implementation.

Then, an endless_loop_on_error feature could be introduced that replaces the abort with a loop {};. This will allow take_mut to be used in no_std environments that don't have unwrapping anyway (so the endless loop will not even be ever entered). Libraries that depend on take_mut should not opt in to that feature (as they might just as well be used in std scenarios), only no_std applications should pull this in.

(Whether it is a good idea then to replace the catch_unwind with the ZST-Drop trick in general I can't tell, but it'd probably help keep the complexity of the distinction low.)

@chrysn
Copy link
Author

chrysn commented Nov 28, 2019

The replace_with crate already implements this fix (if it doesn't get implemented here, maybe link over there for the no_std solution?).

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

1 participant