Function constmuck::zeroed_array [−][src]
pub const fn zeroed_array<T, const SIZE: usize, const LEN: usize>(
_bounds: TypeSize<ImplsZeroable<T>, T, SIZE>
) -> [T; LEN]
Expand description
For safely getting a std::mem::zeroed
[T; N]
.
This function requires that T
implements Zeroable
.
To specify the length of the returned array, TypeSize::zeroed_array
can be used instead.
Example
use constmuck::{zeroed_array, type_size};
const BYTES: [u8; 2] = zeroed_array(type_size!(u8));
const CHARS: [char; 4] = zeroed_array(type_size!(char));
assert_eq!(BYTES, [0, 0]);
// you can use `TypeSize::zeroed_array` like here to pass the length of the returned array.
assert_eq!(type_size!(u8).zeroed_array::<2>(), [0, 0]);
assert_eq!(CHARS, ['\0', '\0', '\0', '\0']);
assert_eq!(type_size!(char).zeroed_array::<4>(), ['\0', '\0', '\0', '\0']);