Make Scalar::from_bits a const fn. #325
Merged
+1
−1
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.
const_fn
is stable since Rust 1.31 (rust-lang/rust#54835) and enables callingScalar::from_bits(..)
from other const fn contexts, potentially saving some overhead here and there.Especially useful in contexts where constants are being built from a bit pattern.
My use case is a constructor for a certain large number, where I'd rather start from a slice and set the correct bits that just hardcode in all 32 bytes at once.
I'm not 100% sure about the compatibility guarantees when switching an existing function to
const
, but I imagine it shouldn't interfere anywhere, since the whole test suite still passes.The other constructors use a call to
.reduce()
, so I didn't bother looking deeper whether they can be madeconst
too.