Issues in asserting Result

Another approach is to use unwrap() when asserting success and unwrap_err() when asserting failure. For example:

assert_eq!(Rank::from_char('2').unwrap(), Rank::_2);

You can use anyhow::Error::downcast to check the error against a specific type:

let err = Rank::from_char('z').unwrap_err().downcast().unwrap();
assert_eq!(err, RankError::NotARank('z')));
2 Likes