Debian Codegraph @

debian/missing-sources/glam-0.24.2/src/features/impl_bytemuck.rs

raw
1 use crate::{
2 Affine2, Affine3A, DAffine2, DAffine3, DMat2, DMat3, DMat4, DQuat, DVec2, DVec3, DVec4,
3 I64Vec2, I64Vec3, I64Vec4, IVec2, IVec3, IVec4, Mat2, Mat3, Mat3A, Mat4, Quat, U64Vec2,
4 U64Vec3, U64Vec4, UVec2, UVec3, UVec4, Vec2, Vec3, Vec3A, Vec4,
5 };
6 use bytemuck::{AnyBitPattern, Pod, Zeroable};
7
8 unsafe impl Pod for Affine2 {}
9 unsafe impl Zeroable for Affine2 {}
10 unsafe impl AnyBitPattern for Affine3A {}
11 unsafe impl Zeroable for Affine3A {}
12
13 unsafe impl Pod for Mat2 {}
14 unsafe impl Zeroable for Mat2 {}
15 unsafe impl Pod for Mat3 {}
16 unsafe impl Zeroable for Mat3 {}
17 unsafe impl AnyBitPattern for Mat3A {}
18 unsafe impl Zeroable for Mat3A {}
19 unsafe impl Pod for Mat4 {}
20 unsafe impl Zeroable for Mat4 {}
21
22 unsafe impl Pod for Quat {}
23 unsafe impl Zeroable for Quat {}
24
25 unsafe impl Pod for Vec2 {}
26 unsafe impl Zeroable for Vec2 {}
27 unsafe impl Pod for Vec3 {}
28 unsafe impl Zeroable for Vec3 {}
29 unsafe impl AnyBitPattern for Vec3A {}
30 unsafe impl Zeroable for Vec3A {}
31 unsafe impl Pod for Vec4 {}
32 unsafe impl Zeroable for Vec4 {}
33
34 unsafe impl Pod for DAffine2 {}
35 unsafe impl Zeroable for DAffine2 {}
36 unsafe impl Pod for DAffine3 {}
37 unsafe impl Zeroable for DAffine3 {}
38
39 unsafe impl Pod for DMat2 {}
40 unsafe impl Zeroable for DMat2 {}
41 unsafe impl Pod for DMat3 {}
42 unsafe impl Zeroable for DMat3 {}
43 unsafe impl Pod for DMat4 {}
44 unsafe impl Zeroable for DMat4 {}
45
46 unsafe impl Pod for DQuat {}
47 unsafe impl Zeroable for DQuat {}
48
49 unsafe impl Pod for DVec2 {}
50 unsafe impl Zeroable for DVec2 {}
51 unsafe impl Pod for DVec3 {}
52 unsafe impl Zeroable for DVec3 {}
53 unsafe impl Pod for DVec4 {}
54 unsafe impl Zeroable for DVec4 {}
55
56 unsafe impl Pod for IVec2 {}
57 unsafe impl Zeroable for IVec2 {}
58 unsafe impl Pod for IVec3 {}
59 unsafe impl Zeroable for IVec3 {}
60 unsafe impl Pod for IVec4 {}
61 unsafe impl Zeroable for IVec4 {}
62
63 unsafe impl Pod for UVec2 {}
64 unsafe impl Zeroable for UVec2 {}
65 unsafe impl Pod for UVec3 {}
66 unsafe impl Zeroable for UVec3 {}
67 unsafe impl Pod for UVec4 {}
68 unsafe impl Zeroable for UVec4 {}
69
70 unsafe impl Pod for I64Vec2 {}
71 unsafe impl Zeroable for I64Vec2 {}
72 unsafe impl Pod for I64Vec3 {}
73 unsafe impl Zeroable for I64Vec3 {}
74 unsafe impl Pod for I64Vec4 {}
75 unsafe impl Zeroable for I64Vec4 {}
76
77 unsafe impl Pod for U64Vec2 {}
78 unsafe impl Zeroable for U64Vec2 {}
79 unsafe impl Pod for U64Vec3 {}
80 unsafe impl Zeroable for U64Vec3 {}
81 unsafe impl Pod for U64Vec4 {}
82 unsafe impl Zeroable for U64Vec4 {}
83
84 #[cfg(test)]
85 mod test {
86 use crate::{
87 Affine2, Affine3A, DAffine2, DAffine3, DMat2, DMat3, DMat4, DQuat, DVec2, DVec3, DVec4,
88 I64Vec2, I64Vec3, I64Vec4, IVec2, IVec3, IVec4, Mat2, Mat3, Mat3A, Mat4, Quat, U64Vec2,
89 U64Vec3, U64Vec4, UVec2, UVec3, UVec4, Vec2, Vec3, Vec3A, Vec4,
90 };
91 use core::mem;
92
93 macro_rules! test_pod_t {
94 ($name:ident, $t:ty) => {
95 #[test]
96 fn $name() {
97 let t = <$t>::default();
98 let b = bytemuck::bytes_of(&t);
99 // should be the same address
100 assert_eq!(&t as *const $t as usize, b.as_ptr() as usize);
101 // should be the same size
102 assert_eq!(b.len(), mem::size_of_val(&t));
103 }
104 };
105 }
106
107 macro_rules! test_any_bit_pattern_t {
108 ($name:ident, $t:ident) => {
109 #[test]
110 fn $name() {
111 let b = [0_u8; mem::size_of::<$t>()];
112 let t: $t = bytemuck::cast(b);
113 // should be the same size
114 assert_eq!(b.len(), mem::size_of_val(&t));
115 // should be zero
116 assert_eq!(t, $t::ZERO);
117 }
118 };
119 }
120
121 test_pod_t!(affine2, Affine2);
122 test_any_bit_pattern_t!(affine3a, Affine3A);
123 test_pod_t!(mat2, Mat2);
124 test_pod_t!(mat3, Mat3);
125 test_any_bit_pattern_t!(mat3a, Mat3A);
126 test_pod_t!(mat4, Mat4);
127 test_pod_t!(quat, Quat);
128 test_pod_t!(vec2, Vec2);
129 test_pod_t!(vec3, Vec3);
130 test_any_bit_pattern_t!(vec3a, Vec3A);
131 test_pod_t!(vec4, Vec4);
132
133 test_pod_t!(daffine2, DAffine2);
134 test_pod_t!(daffine3, DAffine3);
135 test_pod_t!(dmat2, DMat2);
136 test_pod_t!(dmat3, DMat3);
137 test_pod_t!(dmat4, DMat4);
138 test_pod_t!(dquat, DQuat);
139 test_pod_t!(dvec2, DVec2);
140 test_pod_t!(dvec3, DVec3);
141 test_pod_t!(dvec4, DVec4);
142
143 test_pod_t!(ivec2, IVec2);
144 test_pod_t!(ivec3, IVec3);
145 test_pod_t!(ivec4, IVec4);
146
147 test_pod_t!(uvec2, UVec2);
148 test_pod_t!(uvec3, UVec3);
149 test_pod_t!(uvec4, UVec4);
150
151 test_pod_t!(i64vec2, I64Vec2);
152 test_pod_t!(i64vec3, I64Vec3);
153 test_pod_t!(i64vec4, I64Vec4);
154
155 test_pod_t!(u64vec2, U64Vec2);
156 test_pod_t!(u64vec3, U64Vec3);
157 test_pod_t!(u64vec4, U64Vec4);
158 }