sparkl2d_core/utils/
real_struct.rs1use crate::math::{Point, Real, Vector};
2use core::mem;
3
4pub unsafe trait RealStruct: bytemuck::Pod {
6 const SIZE: usize = mem::size_of::<Self>() / mem::size_of::<Real>();
7
8 fn cast(ptr: *const Real) -> *const Self {
9 ptr as *const Self
10 }
11
12 fn cast_mut(ptr: *mut Real) -> *mut Self {
13 ptr as *mut Self
14 }
15
16 fn cast_slice(slice: &[Real]) -> &[Self] {
17 bytemuck::cast_slice(slice)
18 }
19
20 fn cast_slice_mut(slice: &mut [Real]) -> &mut [Self] {
21 bytemuck::cast_slice_mut(slice)
22 }
23}
24
25unsafe impl RealStruct for Real {}
26unsafe impl RealStruct for Vector<Real> {}
27unsafe impl RealStruct for Point<Real> {}