| 39 | |
| 40 | #[track_caller] |
| 41 | fn case<T: Flags + std::fmt::Debug + std::ops::BitXor<Output = T> + std::ops::BitXorAssign + Copy>( |
| 42 | value: T, |
| 43 | inputs: &[(T, T::Bits)], |
| 44 | mut inherent_sym_diff: impl FnMut(T, T) -> T, |
| 45 | mut inherent_toggle: impl FnMut(&mut T, T), |
| 46 | ) where |
| 47 | T::Bits: std::fmt::Debug + PartialEq + Copy, |
| 48 | { |
| 49 | for (input, expected) in inputs { |
| 50 | assert_eq!( |
| 51 | *expected, |
| 52 | inherent_sym_diff(value, *input).bits(), |
| 53 | "{:?}.symmetric_difference({:?})", |
| 54 | value, |
| 55 | input |
| 56 | ); |
| 57 | assert_eq!( |
| 58 | *expected, |
| 59 | Flags::symmetric_difference(value, *input).bits(), |
| 60 | "Flags::symmetric_difference({:?}, {:?})", |
| 61 | value, |
| 62 | input |
| 63 | ); |
| 64 | assert_eq!( |
| 65 | *expected, |
| 66 | (value ^ *input).bits(), |
| 67 | "{:?} ^ {:?}", |
| 68 | value, |
| 69 | input |
| 70 | ); |
| 71 | assert_eq!( |
| 72 | *expected, |
| 73 | { |
| 74 | let mut value = value; |
| 75 | value ^= *input; |
| 76 | value |
| 77 | } |
| 78 | .bits(), |
| 79 | "{:?} ^= {:?}", |
| 80 | value, |
| 81 | input, |
| 82 | ); |
| 83 | |
| 84 | assert_eq!( |
| 85 | *expected, |
| 86 | { |
| 87 | let mut value = value; |
| 88 | inherent_toggle(&mut value, *input); |
| 89 | value |
| 90 | } |
| 91 | .bits(), |
| 92 | "{:?}.toggle({:?})", |
| 93 | value, |
| 94 | input, |
| 95 | ); |
| 96 | |
| 97 | assert_eq!( |
| 98 | *expected, |