For testing purposes, I have two Vecs of references.
If I try to compare them via
assert_eq!, it fails:
assert_eq!(clips, vec![clip_0, clip_1]);
//error[E0369]: binary operation `==` cannot be applied to type `std::vec::Vec<&components::tweens::Tween>`
However, I can compare their elements with
Is there some way to tell
assert_eq! (or these Vec's Eq...) to use
Alternatively, if I'm barking up the wrong tree in terms of that solution - a better approach is appreciated
std::ptr::eq only compares pointers (i.e. memory addresses), not values, so that's probably not what you want here.
components::tweens::Tween needs an
Eq implementation, or you simply can't compare
Tween values. It may be possible to work around this in your code with a wrapper type if
Tween publicly exposes all the data relevant to a comparison, but even that would require constant wrapping and unwrapping.
If you really do want to compare memory addresses, then AFAIK there are no dedicated assert macros for that and
assert!(std::ptr::eq(...)); is the way to go. Even references intentionally do value comparisons because that's overwhelmingly more common, so when you really want addresses you just have to go outside the
Eq trait entirely.
Yeah - this use-case is specifically for running tests where I want to make sure the references match, e.g. that operations like "give me all the tweens at this point in time" are exactly the ones I expect.
Thanks, will stick with the verbose solution for now
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.