Function constmuck::byte_array_of[][src]

pub const fn byte_array_of<T, const SIZE: usize>(
    bytes: &T,
    _bounds: TypeSize<T, IsPod<T>, SIZE>
) -> &[u8; SIZE]
Expand description

Casts &T to &[u8; SIZE]

Requires T to implement Pod.

SIZE is guaranteed to be the size of T by the TypeSize argument.

Example

use constmuck::{TypeSize, byte_array_of};

const ARRAY: &[u8; 4] = byte_array_of(&123456789, TypeSize!(u32));
const BYTES: &[u8] = byte_array_of(&987654321, TypeSize!(u32));

assert_eq!(*ARRAY, 123456789u32.to_ne_bytes());
assert_eq!(*BYTES, 987654321u32.to_ne_bytes());