From 0d5b9aef123a641da74f39f0ac3d0847b0839d50 Mon Sep 17 00:00:00 2001 From: Szymon Walter Date: Mon, 19 Mar 2018 17:23:45 +0100 Subject: [PATCH] add PartialEq impl for Error --- src/error.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/error.rs b/src/error.rs index 8cb3fb6..83be4e2 100644 --- a/src/error.rs +++ b/src/error.rs @@ -24,4 +24,30 @@ impl From for Error { } } +impl PartialEq for Error { + fn eq(&self, rhs: &Error) -> bool { + match (self, rhs) { + (&Error::BadMagic(a), &Error::BadMagic(b)) => a == b, + (&Error::OutOfBounds(a), &Error::OutOfBounds(b)) => a == b, + ( + &Error::BadBlockGroupCount(a1, a2), + &Error::BadBlockGroupCount(b1, b2), + ) => a1 == b1 && a2 == b2, + _ => false, + } + } + + fn ne(&self, rhs: &Error) -> bool { + match (self, rhs) { + (&Error::BadMagic(a), &Error::BadMagic(b)) => a != b, + (&Error::OutOfBounds(a), &Error::OutOfBounds(b)) => a != b, + ( + &Error::BadBlockGroupCount(a1, a2), + &Error::BadBlockGroupCount(b1, b2), + ) => a1 != b1 || a2 != b2, + _ => false, + } + } +} + pub enum Infallible {}