1
0

eq.rs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. use const_serialize::{serialize_eq, SerializeConst};
  2. #[derive(Clone, Copy, Debug, PartialEq, SerializeConst)]
  3. struct Struct {
  4. a: u32,
  5. b: u8,
  6. c: u32,
  7. d: Enum,
  8. }
  9. #[derive(Clone, Copy, Debug, PartialEq, SerializeConst)]
  10. #[repr(C, u8)]
  11. enum Enum {
  12. A { one: u32, two: u16 },
  13. B { one: u8, two: u16 } = 15,
  14. }
  15. #[test]
  16. fn const_eq() {
  17. const {
  18. let data = [
  19. Struct {
  20. a: 0x11111111,
  21. b: 0x22,
  22. c: 0x33333333,
  23. d: Enum::A {
  24. one: 0x44444444,
  25. two: 0x5555,
  26. },
  27. },
  28. Struct {
  29. a: 123,
  30. b: 9,
  31. c: 38,
  32. d: Enum::B {
  33. one: 0x44,
  34. two: 0x555,
  35. },
  36. },
  37. Struct {
  38. a: 9,
  39. b: 123,
  40. c: 39,
  41. d: Enum::B {
  42. one: 0x46,
  43. two: 0x555,
  44. },
  45. },
  46. ];
  47. let mut other = data;
  48. other[2].a += 1;
  49. if serialize_eq(&data, &other) {
  50. panic!("data should be different");
  51. }
  52. if !serialize_eq(&data, &data) {
  53. panic!("data should be the same");
  54. }
  55. }
  56. }