take_mut icon indicating copy to clipboard operation
take_mut copied to clipboard

Allow opt-in to no_std implementations

Open chrysn opened this issue 5 years ago • 1 comments

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 https://github.com/rust-lang/rfcs/issues/2810#issuecomment-559469938 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 avatar Nov 28 '19 13:11 chrysn

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

chrysn avatar Nov 28 '19 14:11 chrysn