diff options
author | HampusM <hampus@hampusmat.com> | 2025-03-22 15:45:49 +0100 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2025-03-23 13:34:24 +0100 |
commit | b0e8e28c720cf467f349319768c2e2050ed25673 (patch) | |
tree | 2cf4674fd333e45f9b169b7ea0d2caef276c04b8 /ecs/src | |
parent | 8f05637edecc1ce16667769b3f501f30439d8a00 (diff) |
feat(ecs): check if value is too large in BitMask::field_prep
Diffstat (limited to 'ecs/src')
-rw-r--r-- | ecs/src/util.rs | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/ecs/src/util.rs b/ecs/src/util.rs index 17436ff..6f7aed7 100644 --- a/ecs/src/util.rs +++ b/ecs/src/util.rs @@ -252,6 +252,8 @@ impl BitMask<u64> #[must_use] pub const fn field_prep(self, field_value: u64) -> u64 { + debug_assert!(field_value < 1 << self.mask.count_ones()); + ((field_value) << self.mask.trailing_zeros()) & (self.mask) } } @@ -319,4 +321,11 @@ mod tests { assert_eq!(BitMask::new(0b11000).field_prep(3), 0b11000); } + + #[test] + #[should_panic] + fn bitmask_field_prep_too_large_value_panics() + { + let _ = BitMask::new(0b001110).field_prep(9); + } } |