-
Notifications
You must be signed in to change notification settings - Fork 102
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Partialeq #206
base: main
Are you sure you want to change the base?
Partialeq #206
Changes from all commits
c6bd80f
4775dd7
80f6dc8
0ac2b35
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -73,6 +73,33 @@ pub enum Error { | |
HostAddressNotAvailable, | ||
} | ||
|
||
impl PartialEq for Error { | ||
fn eq(&self, other: &Self) -> bool { | ||
match (self, other) { | ||
(Error::InvalidGuestAddress(left), Error::InvalidGuestAddress(right)) => left == right, | ||
(Error::InvalidBackendAddress, Error::InvalidBackendAddress) => true, | ||
(Error::HostAddressNotAvailable, Error::HostAddressNotAvailable) => true, | ||
( | ||
Error::PartialBuffer { | ||
expected: left_expected, | ||
completed: left_completed, | ||
}, | ||
Error::PartialBuffer { | ||
expected: right_expected, | ||
completed: right_completed, | ||
}, | ||
) => left_expected == right_expected && left_completed == right_completed, | ||
(Error::IOError(left), Error::IOError(right)) => { | ||
// error.kind should be enough to assert equallity because each error | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While this is true, it does not mean that |
||
// has the kind field set and the OS error numbers can be converted | ||
// to ErrorKind through `sys::decode_error_kind`. | ||
left.kind() == right.kind() | ||
} | ||
_ => false, | ||
} | ||
} | ||
} | ||
|
||
impl From<volatile_memory::Error> for Error { | ||
fn from(e: volatile_memory::Error) -> Self { | ||
match e { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One reason I don't particularly like these kinds of implementations for PartialEq is that it will silently fail when you add a new error type if you don't explicitly add it in the below match as well. I would propose we add a test that just fails when a new variant is added and has a comment something like: "If this failed it means you added a new error type. Make sure you also add that to the
PartialEq
implementation. Once you've done that feel free to fix this test". This will serve as a warning when adding new types. I am also open to other ideas as this is rather dummy 😆