From 017e1e95067406cb7de024014750527b99188330 Mon Sep 17 00:00:00 2001 From: iximeow Date: Sat, 3 Jul 2021 22:13:29 -0700 Subject: update DecodeError impls --- src/protected_mode/mod.rs | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'src/protected_mode/mod.rs') diff --git a/src/protected_mode/mod.rs b/src/protected_mode/mod.rs index 166358b..cacfcbb 100644 --- a/src/protected_mode/mod.rs +++ b/src/protected_mode/mod.rs @@ -13,18 +13,12 @@ use core::cmp::PartialEq; use core::hint::unreachable_unchecked; use yaxpeax_arch::{AddressDiff, Decoder, Reader, LengthedInstruction}; +use yaxpeax_arch::{DecodeError as ArchDecodeError}; use core::fmt; impl fmt::Display for DecodeError { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - match self { - DecodeError::ExhaustedInput => { write!(f, "exhausted input") }, - DecodeError::InvalidOpcode => { write!(f, "invalid opcode") }, - DecodeError::InvalidOperand => { write!(f, "invalid operand") }, - DecodeError::InvalidPrefixes => { write!(f, "invalid prefixes") }, - DecodeError::TooLong => { write!(f, "too long") }, - DecodeError::IncompleteDecoder => { write!(f, "the decoder is incomplete") }, - } + f.write_str(self.description()) } } @@ -2581,6 +2575,16 @@ impl yaxpeax_arch::DecodeError for DecodeError { fn data_exhausted(&self) -> bool { self == &DecodeError::ExhaustedInput } fn bad_opcode(&self) -> bool { self == &DecodeError::InvalidOpcode } fn bad_operand(&self) -> bool { self == &DecodeError::InvalidOperand } + fn description(&self) -> &'static str { + match self { + DecodeError::ExhaustedInput => { "exhausted input" }, + DecodeError::InvalidOpcode => { "invalid opcode" }, + DecodeError::InvalidOperand => { "invalid operand" }, + DecodeError::InvalidPrefixes => { "invalid prefixes" }, + DecodeError::TooLong => { "too long" }, + DecodeError::IncompleteDecoder => { "the decoder is incomplete" }, + } + } } #[allow(non_camel_case_types)] -- cgit v1.1