feat: Implement std::unsafe::zeroed
#1048
Merged
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.
Related issue(s)
Resolves #1017
Requires #1044 to work as it renames the
unsafe
keyword which is used by this PR as a module name.Part of work to implement #988
Description
Summary of changes
Implements
fn zeroed<T>() -> T
to return a zeroed value of any type. This function is generally unsafe to use as the zeroed bit pattern is not guaranteed to be valid for all types. It can however, be useful in cases when the value is guaranteed not to be used such as in aBoundedVec
library implementing a growable vector, up to a certain length, backed by an array. The array can be initialized with zeroed values which are guaranteed to be inaccessible until the vector is pushed to. Similarly, enumerations in noir can be implemented using this method by providing zeroed values for the unused variants.Dependency additions / changes
Test additions / changes
Checklist
cargo fmt
with default settings.Documentation needs
Add
std::unsafe::zeroed
to the documentation of the standard library. Its type signature and usecases should be noted (given above in this PR), and especially the note on its potential unsafeness.Additional context