Skip to content

Commit 9f9c8b9

Browse files
[guest_memory]: Implement PartialEq
Signed-off-by: Alexandru Cihodaru <[email protected]>
1 parent 75b2425 commit 9f9c8b9

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

src/guest_memory.rs

+27
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,33 @@ pub enum Error {
7373
HostAddressNotAvailable,
7474
}
7575

76+
impl PartialEq for Error {
77+
fn eq(&self, other: &Self) -> bool {
78+
match (self, other) {
79+
(Error::InvalidGuestAddress(left), Error::InvalidGuestAddress(right)) => left == right,
80+
(Error::InvalidBackendAddress, Error::InvalidBackendAddress) => true,
81+
(Error::HostAddressNotAvailable, Error::HostAddressNotAvailable) => true,
82+
(
83+
Error::PartialBuffer {
84+
expected: left_expected,
85+
completed: left_completed,
86+
},
87+
Error::PartialBuffer {
88+
expected: right_expected,
89+
completed: right_completed,
90+
},
91+
) => left_expected == right_expected && left_completed == right_completed,
92+
(Error::IOError(left), Error::IOError(right)) => {
93+
// error.kind should be enough to assert equallity because each error
94+
// has the kind field set and the OS error numbers can be converted
95+
// to ErrorKind through `sys::decode_error_kind`.
96+
left.kind() == right.kind()
97+
}
98+
_ => false,
99+
}
100+
}
101+
}
102+
76103
impl From<volatile_memory::Error> for Error {
77104
fn from(e: volatile_memory::Error) -> Self {
78105
match e {

0 commit comments

Comments
 (0)