From 354940536d4f700e7f441090435362e8f6ca219d Mon Sep 17 00:00:00 2001 From: iximeow Date: Mon, 14 Jun 2021 17:46:05 -0700 Subject: experiment --- src/lib.rs | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/lib.rs b/src/lib.rs index e95513d..a5b8767 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -38,32 +38,43 @@ pub trait DecodeError { fn bad_operand(&self) -> bool; } -pub trait Decoder where Inst: Sized + Default { +pub enum ReadError { + ExhaustedInput, + IOError(&'static str), +} + +pub trait Reader { + fn next(&mut self) -> Result; +} + +pub trait Decoder { type Error: DecodeError + Debug + Display; - fn decode>(&self, bytes: T) -> Result { - let mut inst = Inst::default(); + fn decode>(&self, bytes: &mut T) -> Result { + let mut inst = A::Instruction::default(); self.decode_into(&mut inst, bytes).map(|_: ()| inst) } - fn decode_into>(&self, inst: &mut Inst, bytes: T) -> Result<(), Self::Error>; + fn decode_into>(&self, inst: &mut A::Instruction, bytes: &mut T) -> Result<(), Self::Error>; } #[cfg(feature="use-serde")] pub trait Arch { + type Word: Debug + Display + PartialEq + Eq; type Address: Address + Debug + Hash + PartialEq + Eq + Serialize + for<'de> Deserialize<'de>; - type Instruction: Instruction + LengthedInstruction> + Debug + Default; + type Instruction: Instruction + LengthedInstruction> + Debug + Default + Sized; type DecodeError: DecodeError + Debug + Display; - type Decoder: Decoder + Default; + type Decoder: Decoder + Default; type Operand; } #[cfg(not(feature="use-serde"))] pub trait Arch { + type Word: Debug + Display + PartialEq + Eq; type Address: Address + Debug + Hash + PartialEq + Eq; - type Instruction: Instruction + LengthedInstruction> + Debug + Default; + type Instruction: Instruction + LengthedInstruction> + Debug + Default + Sized; type DecodeError: DecodeError + Debug + Display; - type Decoder: Decoder + Default; + type Decoder: Decoder + Default; type Operand; } -- cgit v1.1