Allow initialization using a const fn, and initialization to values other than None #3
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi. This seems to work, and somewhat invalidates the need for the macro too, although I left it and just used static_none to initialize it instead. I don't mind reverting the macro changes if you want -- They are not fully backwards compatible, if someone did
&*THE_STATIC_FROM_THE_MACRO
it would work before (invoke the Deref of the dummy type explicitly) but not after.I wasn't sure what to name the functions, and don't really what I chose a lot, but maybe they're fine. If you'd prefer different names let me know.
The move to
AtomicPtr
forAtomicRef::static_some
is needed because pointer to int in const fn isn't allowed. I kind of doubt it ever will be allowed, given that a relocation will need to be emitted for constructs like this in dynamic libraries on some platforms, andusize
completely obscures that (I was a little surprised it worked withAtomicPtr
, to be honest.I think if you wanted you could clean this up a bit now, since the macro and the
ATOMIC_U8_REF_INIT
are both a little redundant. The crate-level docs probably need updating too since this maybe is a more ergonomic API than the one they show, but I can do that if you want, or I can leave it to you.