Skip to main content

wowlab_engine_domain/rotation/
expr.rs

1//! Expression field types and context population.
2
3pub use wowlab_buffer_contract::FieldType;
4
5const I32_SIZE: usize = 4;
6const F64_SIZE: usize = 8;
7
8pub(super) trait FieldTypeLayout {
9    fn size(self) -> usize;
10    fn alignment(self) -> usize;
11}
12
13impl FieldTypeLayout for FieldType {
14    fn size(self) -> usize {
15        match self {
16            // Bool stored as i32 in DenseBuffer so one store_bool/load_bool primitive covers all bools.
17            FieldType::Bool | FieldType::Int => I32_SIZE,
18            // FieldType is non_exhaustive; Float and unknown variants default to f64 width.
19            _ => F64_SIZE,
20        }
21    }
22
23    fn alignment(self) -> usize {
24        self.size()
25    }
26}
27
28#[cfg(test)]
29mod tests {
30    use googletest::prelude::*;
31    use rstest::rstest;
32
33    use super::*;
34
35    #[gtest]
36    #[rstest]
37    #[case(FieldType::Bool, 4)]
38    #[case(FieldType::Int, 4)]
39    #[case(FieldType::Float, 8)]
40    fn field_type_layout_size_and_alignment(
41        #[case] ty: FieldType,
42        #[case] expected: usize,
43    ) -> Result<()> {
44        verify_that!(ty.size(), eq(expected))?;
45        verify_that!(ty.alignment(), eq(expected))?;
46
47        Ok(())
48    }
49}