diff --git a/fyrox-core/src/lib.rs b/fyrox-core/src/lib.rs index 9553206cb..af6a27af3 100644 --- a/fyrox-core/src/lib.rs +++ b/fyrox-core/src/lib.rs @@ -324,6 +324,12 @@ pub fn array_as_u8_slice(v: &[T]) -> &'_ [u8] { unsafe { std::slice::from_raw_parts(v.as_ptr() as *const u8, std::mem::size_of_val(v)) } } +/// "Transmutes" array of any sized type to a slice of bytes. +pub fn array_as_u8_slice_mut(v: &mut [T]) -> &'_ mut [u8] { + // SAFETY: It is safe to reinterpret memory region of POD type. + unsafe { std::slice::from_raw_parts_mut(v.as_mut_ptr() as *mut u8, std::mem::size_of_val(v)) } +} + /// "Transmutes" array of any sized type to a slice of some other type. pub fn transmute_slice(v: &[T]) -> &'_ [U] { // SAFETY: It is safe to reinterpret data to read it.