-
Notifications
You must be signed in to change notification settings - Fork 111
Implement Eq on ErrorKind? #95
Comments
I guess a |
That would be a good idea, but that's not practical. io::Error, a very common error type, doesn't implement |
Is there a particular recommended way to check the |
I think a match over ErrorKind is fine. If you also want to implement Eq on Error, you may want to pay attention to the backtrace and the error chain. |
ok thanks |
With https://github.com/Arnavion/derive-error-chain/ we may be able to derive Eq if possible. |
I wrote a small macro to assert against the error types that are returned by my library. Not sure if this will be useful to anyone else but I figured I would share 😃 // usage:
// assert_error_kind!(some_err, ErrorKind::MyErrorType)
macro_rules! assert_error_kind {
($err:expr, $kind:pat) => (match *$err.kind() {
$kind => assert!(true, "{:?} is of kind {:?}", $err, stringify!($kind)),
_ => assert!(false, "{:?} is NOT of kind {:?}", $err, stringify!($kind))
});
} |
I might be holding this wrong, but I'd like to write eg
this complains
Is that feasible to add? Or could we add to the documentation some example of the intended way to write this?
I see I can use a destructuring match but that seems a little unnatural in a test.
The text was updated successfully, but these errors were encountered: