Skip to content

Added support for use with no_std #3

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

Merged
merged 4 commits into from
Mar 27, 2019
Merged

Added support for use with no_std #3

merged 4 commits into from
Mar 27, 2019

Conversation

regexident
Copy link
Contributor

This PR does three things:

  1. It makes fn replace_with() & fn replace_with_or_default() available on both stable and nightly Rust with no_std.
  2. It makes fn replace_with_or_abort() available on nightly Rust with no_std via "nightly" feature.
  3. It makes unsafe fn replace_with_or_abort_unchecked() available via "panic_abort" feature.

The latter expects panic = "abort" to be defined in Cargo.toml. Being hidden behind a feature flag it will also be hidden on docs.rs (afaik), which I would consider desirable, actually. It's a "last resort" escape hatch, not an API one would want to get into everybody's hands, without knowing the issues around unwinding.

I chose the unsafe fn …_unchecked() naming pattern, as it's a quite common pattern already.

@alecmocatta
Copy link
Owner

Thanks for the PR @regexident!

I appreciate your explanation and hiding from the docs of replace_with_or_abort_unchecked. I wouldn't be surprised if replace_with_or_abort optimised equivalently under panic = "abort" in release builds. Have you observed this not to be the case? Or does something else about your use case still require it?

Regardless, the PR looks well thought through so I'm very happy to go ahead and merge and release shortly.

@alecmocatta alecmocatta merged commit 639ca0d into alecmocatta:master Mar 27, 2019
@alecmocatta
Copy link
Owner

Merged and released.

After my comment I realised you indended replace_with_or_abort_unchecked for stable no_std rather than for performance. That's fine by me. I am looking forward to deprecating and removing it once aborting/trapping is available in stable no_std. Linking relevant issue rust-lang/rfcs#2512 for future reference.

alecmocatta added a commit that referenced this pull request Oct 17, 2019
spaces rather than hyphens in wip label
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

Successfully merging this pull request may close these issues.

2 participants