binary operation `==` cannot be applied to type `std::result::Result<card::Rank, anyhow::Error>`rustc[E0369](https://doc.rust-lang.org/error-index.html#E0369)
when asserting a Result object.
assert_eq!(Rank::from_char('2'), Ok(Rank::_2));
Any idea what went wrong? What is the idiomatic way to assert a Result?
I'd suggest using assert!(matches!(Rank::from_char('2'), Ok(Rank::_2)) instead.
The issue here is that
a type supports comparing with == (which is what assert_eq! calls under the hood) only if it implements the PartialEq trait
Result<T, E> is PartialEq only if both T and E are PartialEq
anyhow::Error is not PartialEq
Hence you cannot use assert_eq! to compare two values of type Result<Rank, anyhow::Error> (and there's not really anything you can do about this, because you don't control anyhow::Error).
In the future you may be able to use the Result::contains method for this, but that's not stable yet.
anyhow::Error is opaque (it doesn't expose its fields), so you can't pattern-match against it effectively, which is what matches! does. But if you have a more "transparent" error type, like
Ah, unfortunately, I used anyhow::Error as the Error type and ParseCardError::InvalidSymbolForRank is converted to anyhow::Error in the code. Sounds like I couldn't do much here.