`DateTime` auto-derives various traits
The auto-generated code for DateTime
auto-implements Debug
, PartialEq
, Eq
, etc. This means that the Debug
representation and the comparison implementations are based on the underlying pointer and field, not the actual data.
One consequence of this is that we can't compare instances in unit tests:
assert_eq!(
DateTime::new(2f32, 2019, 8, 19, 13, 34, 42f64),
DateTime::new(2f32, 2019, 8, 19, 13, 34, 42f64)
.to_value()
.get()
.unwrap()
.unwrap()
);
The error message isn't very helpful:
thread '[...]' panicked at 'assertion failed: `(left == right)`
left: `DateTime(Shared { inner: 0x7f5020208f20, borrowed: false })`,
right: `DateTime(Shared { inner: 0x7f5020208f70, borrowed: false })`', [...]
The workaround is to check the data fields one by one.
Hash
is also automatically derived, so I guess that we can't use DateTime
in HashMap
s.
Edited by François Laignel