Skip to content

Commit b0b5137

Browse files
Use MaybeUninit::zeroed for gap-filling in bytes_to_data
1 parent ca2ece4 commit b0b5137

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/lib.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
const_maybe_uninit_assume_init,
3939
const_maybe_uninit_assume_init_read,
4040
const_maybe_uninit_uninit_array,
41+
const_maybe_uninit_zeroed,
4142
const_mut_refs,
4243
const_precise_live_drops,
4344
const_ptr_is_null,
@@ -2689,6 +2690,12 @@ impl<const N: usize> StaticVec<u8, N> {
26892690
res[i] = MaybeUninit::new(values[i]);
26902691
i += 1;
26912692
}
2693+
// Fill in any remaining "gaps", or do nothing if `values.len()` is the same as `N`.
2694+
let mut i = values.len();
2695+
while i < N {
2696+
res[i] = MaybeUninit::zeroed();
2697+
i += 1;
2698+
}
26922699
// Convert `res` from an instance of `[MaybeUninit<u8>; N]` to one of `[u8; N]`, and then return
26932700
// it as an instance of `MaybeUninit<[u8; N]>` that can be used to construct a `StaticVec`.
26942701
MaybeUninit::new(unsafe { MaybeUninit::array_assume_init(res) })

0 commit comments

Comments
 (0)